Template include inside related tags

  • Is there a way to include a template inside a <perch:repeater> to output content?


    I' trying to do so but it is not working with the following code

    Code
    1. <perch:related id="tech-specs" collection="Documentos">
    2. <perch:template path="content/document.html">
    3. </perch:related>


    If I write directly the content from the template instead of including it with <perch:template> it does work, but that forces me to duplicate it almost entirely

    Code
    1. <perch:related id="tech-specs" collection="Documentos">
    2. <h1><perch:content id="document_name" type="text"></h1>
    3. </perch:related>
  • Hi Juan,


    • Are you using the related field inside a content region or a collection item?
    • If you turn on debug mode, the debug message should indicate whether Perch is able to find the template content/document.html
    • Try avoiding hyphens in IDs. So instead of tech-specs, use tech_specs


    The id template attribute is a unique identifier for the content field. It is a required attribute. Use letters, numbers and underscores only for an id.

  • Hi Hussein,


    Thank you for the underscore tip, already changed it but it still doesn't work.

    The related field is inside a collection. In the debug output everything seems fine, no templates missing.


    Below is the actual code I'm using (before I simplified it a bit).


    I use an HTML free template for the collection "Modelos"

    Code: model.html
    1. <perch:content id="model_name" type="text" label="Nombre del modelo" title>
    2. <!--* More fields below *-->


    Then I use another template to output the content from that collection

    Code: model_support.php
    1. perch_collection('Modelos', [
    2. 'template' => '_v__model_'.$lang.'.html',
    3. 'filter' => 'slug',
    4. 'value' => perch_get('s'),
    5. ]);
    Code: _v__model_es.html
    1. <perch:related id="tech_specs" collection="Documentos">
    2. <perch:template path="content/_v__document_es.html">
    3. </perch:related>


    "Documentos" collection behaves in the same way, using document.html to create the collection items and other templates for display

    Code: document.html
    1. <!--* More fields above *-->
    2. <perch:related id="models" label="Modelos relacionados" collection="Modelos" required></perch:related>
    3. <!--* More fields below *-->
    Code: _v__document_es.html
    1. <perch:related id="models" collection="Modelos">
    2. <p>
    3. <perch:content id="model_name" type="text"> <span><perch:content id="model_number" type="text"></span>
    4. </p>
    5. </perch:related>
  • Does the template model.html have a perch:related field to relate documents to models?

    HTML
    1. <perch:content id="model_name" type="text" label="Nombre del modelo" title>
    2. <perch:related id="tech_specs" collection="Documentos"></perch:related>



    It looks like you are relating models to documents in document.html, which is absolutely fine, but it means you need to use perch_collection() to get or output these documents:


    PHP
    1. perch_collection('Documentos', [
    2. 'template' => '_v__document_es.html',
    3. 'filter' => 'model.slug',
    4. 'value' => perch_get('s'),
    5. ]);