Forum

Thread tagged as: Question

Multiple template includes

Hi, I know if I include the same template into another one multiple times it will just reuse the same fields as the first one because they have the same ids. Is there some quicker way to deal with changes in this configuration? I have the same chunk of code in numerous places across a site I'm building and if I have to make a change I have to change it in numerous places. I'm using this as one of my templates for blocks. Here's the code for one of the places.

<div <perch:template path="content/section_id.html" /> class="section <perch:template path="content/background_class.html" />">
    <div class="container">
        <div class="row">

            <div class="col-sm-6">

                <perch:if exists="page1 OR section1">
                    <a href="
                             <perch:content id="page1"  divider-before="Box 1" type="text" label="Link to Page" help="The link to the page. You can get this by copying out of brower bar. It will look something like: cismallengines.com/services.php" />
                    #
                    <perch:content id="section1" type="text" label="Link to Section" help="This will be the section id you will have assigned to a section on that page. If you are linking to a section on this page leave the page section blank" />">
                </perch:if>

                <perch:if exists="image1">
                    <img 
                         class="img-responsive img-thumbnail" 
                         src="<perch:content type="image" id="image1" label="Image" width="500" />" 
                         alt="<perch:content type="text" id="alt1" label="Image Description" help="This is a description for  the image. It is used by Google and will only show if the image does not load properly." />" 
                         />
                </perch:if>
                <h3><perch:content id="heading1" type="smarttext" label="Heading" title=true/></h3>
                <p>
                    <perch:content id="paragraph1" type="textarea" label="Paragraph"  size="s" />
                </p>
            <perch:if exists="page1 OR section1">
            </a>
            </perch:if>
            </div>


            <div class="col-sm-6">

                <perch:if exists="page2 OR section2">
                <a href="
                <perch:content id="page2" type="text" label="Link to Page"  divider-before="Box 2" help="The link to the page. You can get this by copying out of brower bar. It will look something like: cismallengines.com/services.php" />
                #<perch:content id="section2" type="text" label="Link to Section" help="This will be the section id you will have assigned to a section on that page. If you are linking to a section on this page leave the page section blank" />">
                </perch:if>

                <perch:if exists="image2">
                    <img 
                         class="img-responsive img-thumbnail" 
                         src="<perch:content type="image" id="image2" label="Image" width="500" />" 
                         alt="<perch:content type="text" id="alt2"label="Image Description" help="This is a description for  the image. It is used by Google and will only show if the image does not load properly."/>" />
                </perch:if>
                <h3><perch:content id="heading2" type="smarttext" label="Heading" title=true/></h3>
                <p>
                    <perch:content id="paragraph2" type="textarea" label="Paragraph"  size="s"  />
                </p>
            <perch:if exists="page2 OR section2">
            </a>
            </perch:if>
            </div>

        </div>
    </div>
</div>
Brian Penner

Brian Penner 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are the template includes not working for this?

No because I would have to use the same one 4 times on this template. It then just repeats the same info when I'd like 4 different things.

Drew McLellan

Drew McLellan 2638 points
Perch Support

So you want to reuse the same code but have small differences each time?

Yes, either that or isolate the template includes so that their id's don't conflict.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, I think we have something planned for Perch 2.9 that might help.

Hi Drew Was there a solution to this problem implemented in Perch 2.9? If so, how does it work? Thanks James