0

I have a template inside a folder located in /templates that is not related to any entry or section:

/folder/test.html

{% extends '_layout' %}

{% set title            = 'myTitle' %}
{% set description      = 'myDescription' %}
{% set variable3        = 'hello' %}


{% block content %}

    <h1>{{ title }}</h1>
    <p>{{ description }}</p>

{% endblock %}

If I want to create a link to this page, I can use the url() function like this:

<a href="{{ url('folder/test') }}">test</a>

How can I access the variables declared on this page?

1 Answer 1

1

I don't think you can. I think the best way to access 'unattached' variables is to create a global field set and attach fields to it. That way you'll be able to access them anywhere.

{{ globalSet1.title }} {{ globalSet1.description }} {{ globalSet1.variable3 }}

1
  • As a side note, in the case of extending a template, the master template (i.e. "_layout") can access variables declared in the child-template directly — if you are trying for example, to define your 'title', 'description', etc. for the your "_layout" master. Jun 25, 2015 at 17:58

Your Answer

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

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