Forum

Thread tagged as: Question

PerchSystem:set_var issue

OK, so I am having trouble passing a variable into a template:

<a href="<?php $url = parse_url($_SERVER['HTTP_REFERER']); /* detect referrer */ 
    if ($url['host'] == $_SERVER['HTTP_HOST']) { /* if domain matches, go back */
        PerchSystem::set_var('back_link', 'javascript: history.go(-1)');
        echo "javascript: history.go(-1)"; } else { PerchSystem::set_var('back_link', '/portfolio/');
        echo '/portfolio/'; } ?>" class="back_anchor">Back to Portfolio</a>
 <?php
perch_content_custom('Portfolio', array(
      'page' => '/portfolio.php',
      'template' => 'portfolio_detail.html',
      'filter' => 'slug',
      'match' => 'eq',
      'value' => perch_get('s'),
      'count' => 1,
    ));
    ?>

As you can see, I am doing two things here: setting the href on the page and also setting the variable for the template.

In the template I have:

<a href="<perch:content id="back_link" type="hidden"/>" class="back_anchor mobile-hide">Back to Portfolio</a>

However the output is empty and no href is applied. I am sure I am doing something silly as usual, just need someone to point it out!

Lisa Morena

Lisa Morena 1 points

  • 3 years ago

Remove type=“hidden”

Well I did have type="text" before, but obviously it showed in the cms form....and still didn't work

You don’t need a “type” when injecting into a template. Have you verified you are actually have data in the variable your passing in?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Adding <perch:showall /> to your template should show you what's available.

Ah yes, that'd be it Robert - taking out the "type" worked. Thanks!