Forum

Thread tagged as: Question

Is it possible to ouput shared content in a "detail" HTML template?

Is it possible to output share content in a "detail"/master HTML template?

e.g. let's say I have a general "refund policy" that I wanted all the individual products to include. I might want something like the following:

Product 1 (output from product_detail.html)

  • Name of product: bike
  • Refund policy: some text here that is always the same <-- this is shared content
  • [Image of bike]
  • [some other info about bike]

Product 2 (output from product_detail.html)

  • Name of product: skateboard
  • Refund policy: some text here that is always the same <-- this is the same shared content
  • [Image of skateboard]
  • [some other info about skateboard]
Jay George

Jay George 2 points

  • 4 years ago

Someone in Slack helped me with this. Here is a solution applied to this example:

<?php
        /* [1] - Create the Refund Policy in the admin */
    perch_content_create('Refund policy', array(
        'template' => 'refund-policy.html',
    ));
?>
<?php
        /* [1] - Assign the Refund Policy to a variable, ready to pass into the Refund Policy template */
    $refund_policy = perch_content_custom('Refund policy', array(
        'template' => 'refund-policy.html',
    ), true);
?>
<?php
        PerchSystem::set_var('refund-policy', $refund_policy);
        perch_content_custom('Refund policy', array(
                'template' => 'refund-policy.html'
        ));
?>

Then in product_detail:

<perch:content id="refund-policy" type="hidden" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

Looks right - except you may need to add encode="false" to that last template tag to stop the content being double-encoded.