I want to list all files in a directory Using PyroCMS.
Using the Files module each client has their own folder, the folder is their User ID
\files\clients\{ID}\
I need something like this.
{{ foreach file in { files:/clients/{{ user:id }} } }}
{{files:current_file_name}}
{{ endif }}
You should be able to do something like this...
{{ files:listing folder="/files/clients/{{ client_id }}" }}
Download {{ name }}
{{ /files:listing }}
You will need to set the client_id variable though. You could set it in your contoller and use:
$this->template
->set('client_id', $client_id)
->build('page-template-goes-here');
Or even use the current user with the tag:
{{ user:id }}
I haven't tested this, but you should be able to get something going.
From here:
http://docs.pyrocms.com/2.1/manual/index.php/modules-and-tags/tag-reference/files
http://docs.pyrocms.com/2.1/manual/index.php/modules-and-tags/tag-reference/user
Related
I created a page of my VIEW - views-view-fields--MYFOOBAR.html.twig
I managed to output the URL of my image field via:
{{ file_url(row._entity.field_image.entity.uri.value) }}
Also I managed how to output normal data fields like text or number:
{{ row._entity.field_MYTEXTFIELD.value }}
Sorry for stupid question, but how can I get URL to my node? I need something like:
<a class="full-item-title" href="NODE URL">{{ row._entity.field_MyH1Text.value }}</a>
{# Link to node page. #}
{{ 'View node page'|t }}
Look at the official documentation: link
Just started using OcteberCMS and now trying to figure out how to translate with rainlab.translate plug-in partial (no, I can't use here {{ ''|_ }} for some reason).
For example, code of layout:
{% partial "footer" %}
I have 2 files in "partials" dir:
footer.htm and footer.fr.htm
but always footer.htm including, but not footer.fr.htm when I'm switch language to fr.
Or maybe is there some way to pass translated variable to partial?
{% partial "sidebar-contacts" city="Vancouver" country="Canada" %}
{% partial "sidebar-contacts" city="{{ 'Vancouver'|_ }}" country="Canada" %}
Thanks in advance.
It's very simple: just pipe variable |_ into translate plug-in like this:
{% partial "sidebar-contacts" city="Vancouver" country="Canada" %}
In file sidebar-contacts:
<div class="sidebar-contacts">
{{ city|_ }}, {{ country|_ }}
</div>
I want to send user data to my univeral header file, which is shown on every page so I can display a "Hi, {{ username }}" message.
How can I do this without getting the data in all controllers of every page?
You can access current user in your twig template via the global variable app, using app.user :
{# If user is connected #}
{% if is_granted('ROLE_USER') %}
Hi, {{ app.user.username }}
{# If user is NOT connected #}
{% else %}
...
{% endif %}
To get the currently logged in user, you can simply write: {{ app.user }}. Then you can access any property from there.
You can also render data from a totally different controller and action (so just from one place) in your twig template by using:
{{ render(controller('AppBundle:Base:myAction')) }}
You can read it over here: https://reformatcode.com/code/c/calling-r39s-optim-function-from-within-c-using-rcpp
I'm trying to add to my layout a header file like so:
Views/layouts/main_layout.blade.php
#include('layouts.header.stylesheets')
the content for that file is:
#section('stylesheets')
{{ stylesheet_link_tag('style.css') }}
#stop
but that doesn't include anything, could you please tell me what am I doing wrong?
If you are including a file, you just do this:
Views/layouts/main_layout.blade.php
#include('layouts.header.stylesheets')
Then in your other file:
{{ stylesheet_link_tag('style.css') }}
You only use #section if you are #yielding to that file
I have an given template file with following content:
Welcome, {{ user }}
In my PHP File I load this content by:
$welcome = file_get_contents(APPPATH . 'classes/Plugins/Core/testplugin/view/frontend/index.html');
So that's in template:
"Welcome, {{ user }}"
Now, if I give this content into my template:
$twig->welcome = $welcome;
$twig->user = "Tom";
Template output (html):
{{ welcome }}
Template output (browser):
Welcome, {{ user }}
My problem: Template engine won't replace my user given in twig string!
Any ideas? I tried using following filters:
{{ welcome|nl2br|raw }}
So you have a string in your template which in itself is a template. Then you need to tell Twig to treat your template variable as a template, otherwise it'll just treat it as string. For this there's the template_from_string function.