Forum

Thread tagged as: Question, Events

How do I display the content from one template in another

I have a template that is set to allow multiple items. I have a "reservation button" that is set to be shared across all pages. As each item is created in perch it must have a reservation button. If I use an include, it includes the reservation-link.html template, but that's not what I want. I want the html output of the reservation-link.html.

I want the output to display the button within each listing. Here is a link to the page so you can see what I mean. Each vehicle has a link to the reservation system. That link is a shared region so I don't want the user to have to fill in the same information each time they add a vehicle. How can I accomplish this?

Kim Mazzola

Kim Mazzola 0 points

  • 5 years ago
Rachel Andrew

Rachel Andrew 394 points
Perch Support

You can use perch_content_custom to output different templates for the same content

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

I don't understand why you would have a reservation button set as a shared region.

The button is set as a shared region because it's the same content (a link to the reservation system) used in several places. IE: the top of every page, the footer of every page and listed with each vehicle. Did you view the page? That would make it very clear.

So, if I had 17 vehicles all linking to the reservation system, that would be cumbersome to update each one should the link to the reservation system change( and that is a possibility). Also, if the link changes to an external system ( which it may in the future) That again becomes cumbersome to edit each spot in which the button is used.

Perch custom content won't work because I can't use that on a content template, can I? It doesn't seem to work when I do that. It does work on a master page, but not on the perch/content/templates/fleet-vehicle.html -- which is the template I used to create each vehicle listing on the referenced page.

My template is below. Using perch_content_custom returns 'reservation-link.html' to my live page.

<div class="fleetListing">
        <div class="row">
                <div class="col-sm-8 rborder">
                        <perch:if exists="image_ext">
                        <img src="<perch:content id="image_ext" type="image" label="Add the Exterior Image." bucket="Fleet_Exteriors" help="Add the Exterior image of the vehicle." divider-before="Exterior Image" />" alt="<perch:content id="img_ext_alt" type="text" label="Alt Text" help="Place alt text here to describe your image. It is helpful to use a keyword" />" class="img-repsonsive" />
                        </perch:if>

                        <perch:if exists="image_int">
                        <img src="<perch:content id="image_int" type="image" label="Add the Interior Image." bucket="Fleet_Interiors" help="Add the Interior image of the vehicle." divider-before="Interior Image" />" alt="<perch:content id="img_int_alt" type="text" label="Alt Text" help="Place alt text here to describe your image. It is helpful to use a keyword" />" class="img-repsonsive" />
                         </perch:if>

                </div>
         <div class="col-sm-4">
            <div class="vehicle_title"><perch:content id="vehicleTitle" type="text" label="Vehicle Type" order="1" title="true" /></div>
             <perch:repeater id="AmenityList" label="Add the Vehicle Amenities">
                <perch:before>
                 <ul>
                 </perch:before>
                    <li><perch:content id="Amenities" type="text" label="Vehicle Amenities" /></li>
                <perch:after>
                    </ul>  
                </perch:after>
                </perch:repeater>
             <?php
    perch_content_custom('Reservation', array(
        'template'=>'reservation-link.html',
    ));
?>
            </div>  
    </div><!-- ./nested row -->             
</div><!-- ./fleet listing -->
Rachel Andrew

Rachel Andrew 394 points
Perch Support

I can't tell you how to architect your site, however the answer to your question is to use perch_content_custom, it may be that you need to make some changes to your original plan to be able to meet this requirement - that happens :)

Personally I would pass the link in as a template attribute, then you can set it in one place. It's not what shared regions are designed for so I don't think the plan you have in mind is going to work.

Thank you, but what do you mean set it as a template attribute? Can you point me in the direction where that is done and let me know how I should approach setting it up that way?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

You can just pass in variables that you set up and then use them as you would use anything else

https://docs.grabaperch.com/docs/templates/passing-variables-into-templates/

Well, again, this approach assumes I know how to code in PHP, which I don't. Also, where does this code go? My master template? My content template? I'm sorry, but that explanation assumes a lot of knowledge I just don't have. How is it adjusted to fit my circumstance? I really don't understand all that code. So sorry, I don't mean to be difficult, it's just that without programming knowledge the code below is a foreign language for me.

<?php 
    PerchSystem::set_var('lang', 'en');
    perch_content_custom('My region', array(
        'template'=>'template.html'
    ));
?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Perch support isn't here to coach you through building a site or to provide tailored solutions to your specific issues. If you're not comfortable with the level of PHP needed to build your solution then you'll need to find someone else to help you with it.

We can point you in the direction of what's available in Perch and help fix issues you're having with the software, but we can't provide every customer with unlimited development consultancy on their project for free.