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
Related
I am trying to encode my Laravel project but unfortunately, Laravel blade templates are not pure PHP .. so the ioncube encoder/reader is unable to encode it properly.
I have tried these ways mentioned here and here, but my views files are not encoded fully ..or not working the way I want (or I have not understood it properly).
so can anyone please help me and tell me to step by step and clear.
These are some of my files inside the blade.php files which are not encodable.
#php
// alignment direction according to language
$dir = "ltr";
$rtlLang = ['ar'];
if(in_array(getOption('language'),$rtlLang)):
$dir="rtl";
endif;
#endphp
{!! getOption('home_page_meta') !!}
<title>#yield('title')</title>
#endif
{{ csrf_field() }}
{{ getOption('currency_symbol') . number_format(Auth::user()->funds,2, getOption('currency_separator'), '') }}
Finally I got an idea and its worked (no one suggested)
you can easily encode your blade by its original code like an example : {{ getOption() }} to <?php echo e(getOption()); ?> . and #if as <php if; ?>
and #section('title', getOption('app_name') . ' - Login') as <?php $__env->startSection('title', getOption('app_name') . ' - login'); ?> and like so. And now you can encoded any blade templates files or laravel projects.
Hope this helpful. Now i have saved my templates file from thief.
I have a do_shortcut and I need to embed it in a twig template. I tried by coping the code in a php file my-code.php:
<?php do_shortcut('[my-code]'); ?>
Next, in the twig page over.twig:
{{ include ('options/my-code.php') }}
/* I also tried */
{% php %}
<?php do_shortcut('[my-code]'); ?>
{% endphp %}
But doesn't work. Any suggestion? Thanks.
You can't do that, you should create a twig extension and transform the php function into a twig function: http://symfony.com/doc/current/cookbook/templating/twig_extension.html
About the include part, create a my_code.html.twig file at app/Resources/views/my_code.html.twig and copy-paste your code from my-code.php
Then you can include that code anywhere like :
{% include 'my_code.html.twig' %}
EDIT: tested and working in symfony3
Try this code:
{{ wp.do_shortcode('[shortcode]')|raw }}
I want to "multilocalize" my Laravel project.
I made my directory structure like this:
lang
- en
- front
- contact.php
-footer.php
And I built my footer like this:
{{ link_to('/', trans('footer.frontpage'))}}
It works perfectly, but when I want localize the other blade pages, for example the contact us page like this:
#lang('front.contact.name')
or this:
{{ __('front.contact.name') }}
or this:
{{ trans('front.contact.name') }}
I only got back on the page:
front.contact.name
What's the problem?
Just use / as directory separator.
{{ trans('front/contact.name') }}
In Blade both "/" and "." function (while the latter is recommended).
But for Lang the "." is unintentionally reserved for file's content (array and any number of child-array), so that we can have both a folder and file with the same name (like both front folder and front.php 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.
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