Laravel: lang file in subfolder - php

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).

Related

Laravel 5.5: Blade forces https on external URLs

i'm displaying external Website Links from my Users in a Profile Page. The URL Format is: www.xyz.com. When i put a http:// before the {{ url }} Laravel changes the Protocoll automatically to https://. In the Result a lot of the Websites don't open properly. I set the APP_URL in the .env File to
https://domain because i want to use SSL in the App.
Laravel (Blade) is removing the http:// from the URL when i just want to print the Variable too. Even when i put http:// right in front the URL in the DB (MySQL) i still have the same problem.
All i do in the Controller is:
$user = \App\User::find($id);
After 2 days of research i'm reaching out to the community. Basically i'm searching for something like secure_url() inverse.
What i tried:
{{ url('http://'.$url) }}
{!! url('http://'.$url) !!}
{!! url(e('http://'.$url)) !!}
<a href="http://{{ $url }}">
{{ $url }}
Putting the Protocoll right in the DB
What do i not get here? Thank you for any help.
EDIT
Laravel does this only when i visit my site over https.
UPDATE & SOLUTION
It was the problem of the Laravel Cache Speed Package. I deactivated it and everything was back to normal. My fault, my bad.

Using Twig variable inside Twig variable

I have a language JSON file containing the text of each page on my website. So to fetch the title of the page, I'll do something like
{{ translation.page1.title }}
In order to fetch the title for page 1.
I already have a page variable that tells me the name of the page, I was wondering if it was possible to do something to avoid having a giant if statement for each page such as:
{{ translation.{{ page }}.title }}
I've looked through the twig doc and I have no idea.
Try to put your variable between brackets
{{ translation[page].title }}
That should be work

Using partial view, and second controller on one view in Symfony 2

I have a question: how can 1 view/page use 2 controllers to display different data?
For example:
1) Page displays DVD's information using DvdController.
2) On that same page I want to use a Template/Partial view, that displays list of actors, and that list should come from the second ActorsController.
I can add a template view inside another page but the second controller doesn't work:
MainPage on URL: website/dvd
{% block body %}
<div>
<h1>{{ dvd.title }} </h1>
</div>
<div>
{{ include('DVDBundle:Actors:actors.html.twig') }}
</div>
{% endblock %}
Above I use the partial view actors.html.twig to show the actors, strangely the html code/div's and so on are actually displayed and working on the page, however the controllers(ActorsController) method that meant to return this partial view is not executed for some reason.?
But if I go to the view directly via link: website/actors then its working.
The Symfony documentation on embedded controllers explains this nicely.
In short, you will need to do something like this in your template file:
<div>
{{ render(controller(
'DVDBundle:Actors:actors',
{ ... parameters to the controller action here ... }
)) }}
</div>
The important thing is calling the render function, which allows a controller to be rendered, as opposed to simply includeing a template. (This assumes that your have an ActorsController with an actorsAction method; change the names as appropriate to your controller.)

Laravel Blade doesn't include partial

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

how to link back to index.php in the fat free framework

I have created some routes with associated html links and they all work fine, except the homepage route (link).
So when i press on the home link to go back to index.php, it does not work.
I have already tried using a slash as key in my array, but that takes me too far back.
What can i put in the array so it links back to index.php?
here is the code in index.php
$f3=require('lib/base.php');
$f3->set('AUTOLOAD', 'model/');
$f3->set('UI','view/');
$f3->route('GET /', 'content->home');
$f3->route('GET /about','content->about');
$f3->route('GET /jobs','content->jobs');
$f3->set('menu',array(''=>'home','about'=>'about','jobs'=>'jobs'));
$f3->run();
here is the code in my template header.htm
<repeat group="{{ #menu }}" key="{{ #key }}" value="{{ #link }}">
<a href="{{#key}}" {{ #pagetitle==#link?' class="active" ':' ' }} >{{ #link }}</a>
</repeat>
The problem is not the php code. The issue is that your app runs in a sub-directory, that's why <a href="/"> brings you up to the webroot. Try to use an absolute link path here.
After taking a good look at the fat free framework documentation i found this:
$f3->get('BASE');
This is a ff global that gets you back to index.php
I've saved it in my own variable like so:
$f3->set('home',$f3->get('BASE'));
{{ #menu.top.home }}
<a class="{{ #view=='mainpage.html'? 'active ' : ''}}item" href="{{ #BASE }}/home">{{ #menu.top.home }}</a>
Localization example with URL link assembling

Categories