We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22369
    • 11 Posts
    Hi,

    I have been writing a small snippet from which i need to return a variable (a URL) that will be used in 3 or 4 places within 1 template.

    My question is what is the best way to print the returned URL to multiple places - I’m assuiming that by placing the snippet name ([[redirect]]) in multiple places it runs the code multiple times also. So, is there a way of creating a variable that can be reused?

    for example:

    Snippet name:
    [[redirect]]

    Cut down php snippet code:
    $redirect = "somedomain.com/particular_folder";

    I have tried the following methods to print out the variable to the template:

    Create another snippet with the php code (’echo $redirect’)
    [[404-campaign-redirect]]

    Inline php directly within the template
    <?php echo $redirect ?>

    Placeholder
    +redirect+

    Thanks in advance for any help on this.



      • 4041
      • 788 Posts
      Create your snippet which will create the placeholder, for this example I named it "my_redirect".
      Call it in the top of your template: [[my_redirect]] or [!my_redirect!]
      Now you should be able to use the placeholder [+my_redirect+] anywhere you want the output to appear.

      <?php
      // my_redirect
      // create placeholder [+my_redirect+]
      $modx->setPlaceholder('my_redirect','somedomain.com/particular_folder');
      ?>
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 4172
        • 5,888 Posts
        try in your snippet:

        <?php
        $redirect = "somedomain.com/particular_folder";
        $modx->setPlaceholder('myredirect',$redirect);


        in your template where you need it:

        [+myredirect+]


        [Edit]
        Breezer was faster with the same suggestion. laugh
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 22369
          • 11 Posts
          Great thanks, worked like a charm.

          Nice to see a little competition in the ranks wink