Announcement

#1 2019-03-13 19:04:04

Undergrid
Member
2019-03-13
25

Passing a parameter into an Additional Pages page?

Hi All,

I was wondering if it was possible (and if so, how?) to pass a parameter (for example a category id or photo id) into a page added using Additional Pages?

Thanks.

Piwigo version: 2.9.4
PHP version: 7.0.30
MySQL version: Ver 15.1 Distrib 10.1.26-MariaDB

Offline

 

#2 2019-03-14 21:01:51

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

Re: Passing a parameter into an Additional Pages page?

Hi :-)

what do you want to do exactly?


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 2019-03-14 21:34:34

Undergrid
Member
2019-03-13
25

Re: Passing a parameter into an Additional Pages page?

Hi ddtddt

I have a page listing the root categories of my site and showing the last 5 added images.  I'd like a link for each category that would take the user to a new page that shows more of the recent images for the selected category and maybe even page through the rest of the images in the category and it's children.

Offline

 

#4 2019-03-15 06:30:12

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

Re: Passing a parameter into an Additional Pages page?

Hi :-)

Have you test [extension by plg] PWG Stuffs


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

 

#5 2019-03-15 11:48:04

Undergrid
Member
2019-03-13
25

Re: Passing a parameter into an Additional Pages page?

Thanks for the suggestion.

I've had a look and while it does do some of the things, it's a bit limited.  I can't see any way to put a block on it's own page (for example) and it doesn't allow paging through more images in a category (for example if I'm showing the last twenty of a particular category, there's no way to add a link to see 21 to 40).

Offline

 

#6 2019-03-16 08:19:34

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

Re: Passing a parameter into an Additional Pages page?

Hi :-)

you can see code and make personal plugin


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

 

#7 2019-03-16 22:59:20

Undergrid
Member
2019-03-13
25

Re: Passing a parameter into an Additional Pages page?

I assume it's okay to answer my own question here, and hopefully someone else will find this useful later.

So rather than try and pull apart PWG Stuffs, I took a different approach more akin to my original request.

I added the following to my Personal Plugins:

Code:

add_event_handler('AP_render_content', 'addUrlTokens');
function addUrlTokens($content) {
  global $tokens;
  
  $data = '<script type="text/javascript">var tokens = {}; ';
  if ((isset($tokens)) && (count($tokens) > 0)) {
    for ($i=0; $i < count($tokens); $i+=2) {
      if (isset($tokens[$i+1])) {
         $data .= "tokens['" . $tokens[$i] . "'] = '" . $tokens[$i+1] . "';";
      }
    }
  }
  $data .= '</script>';
  
  return $data . $content;
}

This takes all the tokens from the URL and creates them as a javascript hash at the start of Additional Page's pages called tokens.  So you'll end up with something like this at the top of your content:

Code:

<script type="text/javascript">var tokens = {}; tokens['page'] = 'test2';tokens['wibble'] = 'cli';</script><style type="text/css">

In this example, the URL used was "index.php?/page/test2/wibble/cli"

You can then use it in your javascript, something like:

Code:

<div class="d-flex justify-content-center">
  <div id="data" class="mt-2"></div>
</div>

<script type="text/javascript">
Object.keys(tokens).forEach(function (key) { 
    var value = tokens[key]
    $('#data').append('<div>' + key + ' = ' + value + '</div>');
});
</script>

Obviously you don't need to iterate the array, but do remember to check the key exists before attempting to use it.

Edit: Obviously this won't work with stand-alone pages, but then you probably have access to the URL parameters using more standard methods.

Last edited by Undergrid (2019-03-16 23:02:32)

Offline

 

Board footer

Powered by FluxBB

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