Announcement

  •  » Extensions
  •  » cat_modify.tpl doesn't show my text

#1 2018-10-09 14:02:56

HarryF
Member
2013-09-25
28

cat_modify.tpl doesn't show my text

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:

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

 

#2 2018-10-09 23:16:56

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: cat_modify.tpl doesn't show my text

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');


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#3 2018-10-10 08:28:51

HarryF
Member
2013-09-25
28

Re: cat_modify.tpl doesn't show my text

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

 

#4 2018-10-12 19:02:53

HarryF
Member
2013-09-25
28

Re: cat_modify.tpl doesn't show my text

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.

Code:

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

 

#5 2018-10-13 10:09:47

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: cat_modify.tpl doesn't show my text

Hi :-)

Where you want exactly add information ?

are you verify if "index" exist as $template?


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#6 2018-10-13 10:40:53

HarryF
Member
2013-09-25
28

Re: cat_modify.tpl doesn't show my text

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

 

#7 2018-10-13 18:14:05

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: cat_modify.tpl doesn't show my text

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


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#8 2018-10-13 20:32:15

HarryF
Member
2013-09-25
28

Re: cat_modify.tpl doesn't show my text

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.

Code:

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

 

#9 2018-10-14 08:23:28

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: cat_modify.tpl doesn't show my text

Hi :-)

can you test replace

HarryF wrote:

$search = '#{if !empty($CONTENT)}{$CONTENT}{/if}#';

by

$search = '/{if !empty\(\$CONTENT\)}{\$CONTENT}{/if}/is';


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#10 2018-10-14 17:09:06

HarryF
Member
2013-09-25
28

Re: cat_modify.tpl doesn't show my text

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()

Code:

$name = "This is a test";
$template->assign('PMV_NAME', $name);

and the replacement was this

Code:

  $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

 

#11 2018-10-15 06:21:45

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: cat_modify.tpl doesn't show my text

Hi :-)

can you test with simple  $search =
for verify function is ok

after we works on regext


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 

#12 2018-10-16 19:32:40

HarryF
Member
2013-09-25
28

Re: cat_modify.tpl doesn't show my text

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

 

#13 2018-10-17 06:08:34

ddtddt
Piwigo Team
Quetigny - France
2007-07-27
7207

Re: cat_modify.tpl doesn't show my text

Hi :-)

ddtddt wrote:

Hi :-)

can you test replace

HarryF wrote:

$search = '#{if !empty($CONTENT)}{$CONTENT}{/if}#';

by

$search = '/{if !empty\(\$CONTENT\)}{\$CONTENT}{/if}/is';

can you test

$search = '/{if !empty\(\$CONTENT\)}{\$CONTENT}{\/if}/';


You love Piwigo so don't hesitate to participate, learn more on the "Contribute to Piwigo" page. If you don't have much time for contribution, you can also help the project with a donation.

Offline

 
  •  » Extensions
  •  » cat_modify.tpl doesn't show my text

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact