Forum

Thread tagged as: Question, Problem

Sharing a particular element from a template in another area of the site?

I have a template containing two images and two headers and have allow multiple items applied. There is also pagination applied to this.

I need to share just the image part of the template in another area of the site. I basically want to create a shared region but only sharing one element of the region rather than the whole template.

Is this possible and if so how would I go about it?

Many thanks!

David Springate

David Springate 0 points

  • 7 years ago

You'll want to use perch_content_custom

docs: https://docs.grabaperch.com/docs/content/perch-content-custom/

I came across this post searching the forum for the answer but it confused me a bit, could anyone explain in a bit more detail...

docs: https://support.grabaperch.com/index.php?pg=forums.posts&id=908

Drew McLellan

Drew McLellan 2638 points
Perch Support

In what way are you confused? Which bit doesn't make sense to you?

Create a template containing only the subset of content/markup that you want to display, and then use perch_content_custom() to display the region setting the new template in the template option.

Here is an example of what i think you want

<?php perch_content_custom('Gold Services', array(
                'page'=>'/services.php',
                'template'=>'price.html'
                ));
?>

then your template

<perch:content type="text" id="price" label="Price"/>

This would look for the region Gold Services on the page services.php and you have set up the template to only display the content with the id of price

In my index.php I'm using...

    <?php perch_content_custom('grid', array(
        'paginate'=> true,
        'count'=> 4,
    ));?>

to call the main template. Then in another div i have

      <?php perch_content_custom('grid');?>

to pull in the second lot but I'm pulling in the whole template still. I'm confused on how I just pull in the images? So you are saying I need to create another template just containing an image field and then use perch_content_custom to call that template?

Really sorry just finding this hard to get my head around.

Do I need 2 perch_content_custom ?

Aha that seems to be the answer I was looking for Dexter, I did...

     <?php perch_content_custom('grid', array(
        'page'=>'/index.php',
        'template'=>'largeimage.html'
     ));?>

and then put the img field in the largeimage.html template


<img class="mainImages" src="<perch:content type="image" id="image" label="Grid Image" required="true" width="781" height="521" />" alt="<perch:content type="text" id="alt" label="Image Alt Description" required="true" />" />

Thanks very much Dexter for your help!

No problem, glad you got it working

Oh and to answer your question you only need the one perch_content_custom the other remains perch_content