Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using variable in template <include> directive. #1280

Open
eliargon opened this issue Mar 27, 2024 · 2 comments
Open

using variable in template <include> directive. #1280

eliargon opened this issue Mar 27, 2024 · 2 comments

Comments

@eliargon
Copy link

eliargon commented Mar 27, 2024

Within a template I defined a awLib as a directory with
<set awLib="./awLib/"/>
and the I can use it as a variable inside
src="..." or href="..." in HTML and <script> directive.
These line Work!

<link rel="stylesheet" href="{{@awLib}}css/misc.css"> 
<script src="{{@awLib}}js/misc.js"></script>

However, it does not work when I try to use the var (in the same way) in a template or directive.
The following line DOES NOT WORK!
<F3:include href="{{@awLib}}page_header.tpl" />
The only way to make it work it to use it as concatenated string.
The following line WORKS!
<F3:include href="{{@awLib.'page_header.tpl'}}" />
Any explaination?

@ikkez
Copy link
Collaborator

ikkez commented Mar 28, 2024

It's documented right that.

You can also have dynamic content in the form of:

<include href="{{ @content }}" />
// OR
<include href="{{ 'templates/layout/'.@content }}" />

// WRONG
<include href="templates/layout/{{ @content }}" />

https://fatfreeframework.com/3.8/views-and-templates#TemplatesWithinTemplates

The real explanation behind is, that it's way more complex for template directives to handle such a case, and it must be implemented in every directive itself, hence there's no one fits all solution. The main template directives that come with F3 only supports static string or token usage for its attributes and no mixed usage.. at least it's documented right that.. hence you have to use the string concatenation within the token to make it work.

@eliargon
Copy link
Author

eliargon commented Mar 30, 2024

Thanks Christian.
I have tried to use a library of shared template which I connected to the Document Root via a symbolic link.
When a template is included, F3 assumes the base folder to be UI (as defined in config.ini) .
For example: in config.ini Ihave

UI=./uiW3/
W3tpl=../awLib/W3/

Note: the W3tpl is a shared libray. So when using a shared template from the library, I have to define the path from the base UI so I step one folder back.
Thus : in my layout.tpl file I can have
<F3:include href="./pg/pg_footer.tpl"/>
which assumes a path starting with UI (https://example.com/uiW3/pg/pg_footer.tpl)
or
<F3:include href="'{{@W3tpl.'pg/pg_footer.tpl'}}"/>
which assumes a path starting with ../awLib/W3 (https://example.com/awLib/W3/pg/pg_footer.tpl)
Thanks again for a wonderfull framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants