Hello,
another question from someone who is willing to learn.
Is the handling of cat_modify.tpl different from picture_modify.tpl? I'm just trying to assign data to that temple in the same way as I already did it in picture_modify.tpl which works pretty well. Because I'm just learning how to create plugins I'm working based on the copyrights plugin.
That means, I set the prefilter with this code:
function PMV_set_prefilter_cat_modify() { global $template; $template->set_prefilter('cat_modify', 'PMV_cat_modify'); }
Then I wrote a function called 'PMV_cat_modify'. As I could see the data I got from the database and which I assigned to the template with $template->assign('PMInfo', $PMVInfo); are as they should be. But nothing appears on the admin part of the category.
Any idea what I may did wrong?
Thanks
Harry
Piwigo 2.9.4
Betriebssystem: Linux
PHP: 7.0.32-0ubuntu0.16.04.1 (Info anzeigen) [2018-10-09 13:51:10]
MySQL: 5.7.23-0ubuntu0.16.04.1 [2018-10-09 13:51:10]
Grafikbibliothek: External ImageMagick 6.8.9-9
Offline
Hi :-)
in file cat_modify.php line 406
$template->assign_var_from_handle('ADMIN_CONTENT', 'album_properties');
--------------
in your code
$template->set_prefilter('cat_modify', 'PMV_cat_modify');
can you test
$template->set_prefilter('album_properties', 'PMV_cat_modify');
Offline
Thank you very much!
Now the admin page shows what I wanted to. I guess for a newbie like me that was impossible to find out.
Let's see if my further modifications will also work as they should.
Harry
Offline
Hi again!
As I almost thought the next step to my successful plugin is not working :-( .
I guess it's because I'd like to add information to the index.tpl. My naive thoughts were to create a file like the image.php from the copyrights plugin and modify it.
But this code seems to be wrong because nothing appears on the category page by adding information before {if !empty($CONTENT)}{$CONTENT}{/if} in the index.tpl.
add_event_handler('loc_begin_index', 'pmv_set_prefilter_add_infos_to_index', 50 ); add_event_handler('loc_begin_index', 'pmv_add_index_vars_to_template'); function pmv_set_prefilter_add_infos_to_index() { global $template; $template->set_prefilter('index', 'pmv_add_infos_to_index'); }
Maybe someone could give me a hint.
Thanks
Harry
Offline
Hi :-)
Where you want exactly add information ?
are you verify if "index" exist as $template?
Offline
I checked out that the category view is created by piwigo/themes/default/templateplate/index.tpl (I simply added a few characters manually and they were shown in my front end).
I want to add some information after the content description and before the content itself. That means line 165 in the mentioned index.tpl.
Last edited by HarryF (2018-10-13 10:41:25)
Offline
Hi :-)
HarryF wrote:
I checked out that the category view is created by piwigo/themes/default/templateplate/index.tpl (I simply added a few characters manually and they were shown in my front end).
I want to add some information after the content description and before the content itself. That means line 165 in the mentioned index.tpl.
ok
can you post your code function -> pmv_add_index_vars_to_template
Offline
I only wrote a few lines for testing yet. Maybe the variable for the category id is wrong again but this is not the problem. When I just try to assign simple text without any data from the database nothing is shown on the front end.
function pm_add_infos_to_index($content, &$smarty) { // Add the information before the content $search = '#{if !empty($CONTENT)}{$CONTENT}{/if}#'; $replacement = ' <p> {$PMV_MANUFACTURER}<br> {$PMV_NAME}<br> {$PMV_YEAR}<br> </p> {if !empty($CONTENT)}{$CONTENT}{/if} '; return preg_replace($search, $replacement, $content, 1); } // Assign values to the variables in the template function pm_add_index_vars_to_template() { global $page, $template, $prefixeTable; // Show block only on the category page if ( isset($_GET['cat_id']) ) { // Get the information that belongs to the current category $query = sprintf(' select * FROM %s WHERE cat_id = %d ;', PMINFO_DATA, $_GET['cat_id']); $result = pwg_query($query); $row = pwg_db_fetch_assoc($result); // Get the data from the chosen row $manufacturer = $row['manufacturer']; $name = $row['name']; $year = $row['year']; // Sending data to the template $template->assign('PMV_MANUFACTURER', $manufacturer); $template->assign('PMV_NAME', $name); $template->assign('PMV_YEAR', $year); } }
Offline
Hi :-)
can you test replace
HarryF wrote:
$search = '#{if !empty($CONTENT)}{$CONTENT}{/if}#';
by
$search = '/{if !empty\(\$CONTENT\)}{\$CONTENT}{/if}/is';
Offline
Thanks for the hint. Unfortunately it doesn't work.
As I realized that it may be difficult to use template variables within the replacement search I tried another place in the template and simply assigned a text with
function pmv_add_index_vars_to_template()
$name = "This is a test"; $template->assign('PMV_NAME', $name);
and the replacement was this
$search = '#FILE_CHRONOLOGY_VIEW} {/if}#'; $replacement = ' FILE_CHRONOLOGY_VIEW} {/if} <p> {$PMV_NAME}<br> </p> ';
...without success.
Last edited by HarryF (2018-10-14 17:15:35)
Offline
Hi :-)
can you test with simple $search =
for verify function is ok
after we works on regext
Offline
Hello!
I did it and it worked. I replaced the title </h2> of the index.tpl with my simple text function and it was shown on the category page front end. I also found out that the category is stored in $page['category']['id'].
Now I only need to know how to put my text at the place I want it to. I guess the problem are the smarty functons inside the template which can't be simply replaced by preg_replace.
On the other hand: Maybe I rebuilt the page a little bit by putting my additional information directly under the page title as I did it for testing. I guess that would be the easiest way to do.
However, then it still would be interesting for later use how to replace smarty functions inside the template.
Harry
Offline
Hi :-)
ddtddt wrote:
Hi :-)
can you test replaceHarryF wrote:
$search = '#{if !empty($CONTENT)}{$CONTENT}{/if}#';
by
$search = '/{if !empty\(\$CONTENT\)}{\$CONTENT}{/if}/is';
can you test
$search = '/{if !empty\(\$CONTENT\)}{\$CONTENT}{\/if}/';
Offline