0

For Structured entries, I always have about the same folder structure. If I could access the parent's folder name, I woudn't have to change the {% includes %} when copying a folder.

e.g.:

blog
---_common
---_entry
---_listing
---index

so _entry looks like this:

{% extends "_layouts/_layout" %}

{% block content %}
    {% include "blog/_common" %}
{% endblock %}

and _listing looks like this:

{% set params = { section:'blog', limit: gl_config.cf_blog_limit} %}
{% paginate craft.entries(params) as entries %}

    {% for entry in entries %}
        {% include "blog/_common" %}
    {% endfor %}

    {% include "_includes/_pagination" %}

{% endpaginate %}

They look almost the same for every structure channel I use (e.g. discography, pressreleases, projects etc etc.)

If I could use {% include "PARENT_FOLDER_NAME/_common" %}

I could just duplicate the folder and don't have to worry about these templates!

btw: the _common template looks about like this:

<article class="listing_item format">

    <div class="listing_heading toggle_content">
        <div class="listing_heading_date">
             <span class="h1">{{ entry.postDate | date("d") }}</span>
             {{ entry.postDate|date("F Y") }}
        </div>
        <div class="listing_heading_title">
            <h1>{{ entry.title }}</h1>

            {% set tags = entry.cf_blog_tags %}

            {% if tags | length %}
                {% for tag in tags %}
                    {{ tag.name }} 
                {% endfor %}
            {% endif %}         
        </div>
    </div>
    <div class="listing_content">
        {# 
            Content Matrix text / images / files / quotes / slideshows / videos etc..
        #}
        {% include "_includes/_content_blocks" %}

        <p><a href="{{ entry.url() }}">Permalink</a></p>

        {# Edit #}
        {% include "_includes/_edit" %} 
    </div>
</article>
2
  • If the _common template is the same for all then can't you just place it in it own folder that is shared by all, and never have to change the parent folder? (or vice-versa depending on which is the static part). Commented Nov 4, 2014 at 22:59
  • Please don't use meta-tags. Why did you add [feature-request]?
    – nicael
    Commented Nov 12, 2014 at 14:01

1 Answer 1

2

Have you tried setting a variable and passing it down into your include?

{% set parentFolder = craft.request.getFirstSegment %}

Then pass parentFolder (or whatever you name it) down? This of course assumes your first segment is the name of your folder tree.

2
  • Hi Mark, I didn't test it, but I am pretty sure that it must work. Thanks for pointing me into the right direction... You just gotta love twig! thanks
    – outline4
    Commented Nov 11, 2014 at 15:21
  • Happy to help! And yes TWIG rocks!! Commented Nov 11, 2014 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.