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

    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

    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?

    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:

    1. perch_collection('Documentos', [
    2. 'template' => '_v__document_es.html',
    3. 'filter' => 'model.slug',
    4. 'value' => perch_get('s'),
    5. ]);
  • Does the template model.html have a perch:related field to relate documents to models?

    Yes, it has. That's how I relate documents to models.

    I was trying to do it all with one template but I realised it wasn't possible, so now I'm using this in my page template.

    However, I still have one issue. I am relating as well documents to documents, using blocks

    HTML: document.html
    1. <perch:blocks label="Secciones">
    2. <perch:template path="content/_b__text.html">
    3. <perch:template path="content/_b__features.html">
    4. <perch:template path="content/_b__figure.html">
    5. <perch:template path="content/_b__symbols.html">
    6. <perch:template path="content/_b__warning.html">
    7. <perch:template path="content/_b__labels.html">
    8. <perch:template path="content/_b__document.html">
    9. </perch:blocks>
    HTML: _b__document.html
    1. <perch:block type="document" label="Documento">
    2. <perch:related id="inserted_doc" collection="Documentos" label="Documento" max="1">
    3. </perch:related>
    4. </perch:block>

    I haven't found a way to display all the content created using with the blocks for the embedded document. Is it possible? Or should the <perch:related collection="Documentos"></perch:related> be outside the blocks?