We have been white-labelling our soloution using Laravel's translate functions.
We have now got to the stage where we are working on email templates.
The question is: Is there any way we can insert these translation variables into inline css?
We have already managed to white-label the website CSS, but obviously, the email styling would need to be treated differently as it is all inline.
Here, for example, is the footer of the emails:
<tr style="background: #333333;">
<td style="padding: 30px 120px;">
<p class="white" style="color: #fff; line-height: 32px;">
{{ trans('region.name.name', [], $locale) }}© {{ date("Y") }}
<br />
{{ trans('region.emails.support.email', [], $locale) }} | {{ trans('region.phoneFriendly', [], $locale) }}<br>
</p>
</td>
</tr>
You can see:
{{ trans('region.name.name', [], $locale) }}
and
{{ trans('region.emails.support.email', [], $locale) }}
and
{{ trans('region.phoneFriendly', [], $locale) }}
Populate the footer with contact details.
What I am wondering is, is there a way to insert hex codes into the style elements, like this:
<p class="white" style="color: {{ trans('region.emails.support.email', [], $locale) }}; line-height: 32px;">
Obviously, that doesn't work but should illustrate what we are trying to achieve.
Insights massively appreciated. Asking on behalf of my developers to see if I can save them some time.
I think you can do it by using an escaped function like
{!! trans('nav.find') !!}
so in your case, it would be
<p class="white" style="color: {!! trans('region.emails.support.email', [], $locale) !!}; line-height: 32px;">
BTW don't you think that the value should come from the database instead of from the locale's file.
Related
I want to set two Text fields in one row in the from class. That they loke like this:
Name/surname ______ _______
I can't find something in the Internet.
I use this code in the Form class:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextareaType::class)
->add('surname', TextareaType::class);
}
But this will be shown like this:
Name ____
surname ____
and this is wrong in my situation. Is it possible to do that in the form class?
Thanks for your help.
You can show your form_rows in a more custom way by doing this:
Instead of showing your form in the more universal way:
{{ form_start(myForm) }}
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
You can, in fact, do the next:
{{ form_start(myForm) }}
{{ form_row(myForm.field1) }}
{{ form_row(myForm.field2) }}
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
This will allow you to show those rows how you want with extra arguments, and it will continue to show the rest, so you do not need to use form_row for every row once you have started using it.
Now, you can achieve what you are asking using display: flex, and setting it's direction as row.
Using bootstrap:
{{ form_start(myForm) }}
<div class = "d-flex flex-row">
{{ form_row(myForm.field1) }}
{{ form_row(myForm.field2) }}
</div>
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
Without bootstrap:
{{ form_start(myForm) }}
<div style = "display: flex; flex-direction: row;">
{{ form_row(myForm.field1) }}
{{ form_row(myForm.field2) }}
</div>
{{ form_widget(myForm) }}
{{ form_end(myForm) }}
You can put the label you want only to field1, and so, field 2, without a label, will appear as you are asking, next to the input field of field 1.
I'm using Blade templates to configure emails. I have a header.blade that looks like this:
<tr>
<td class="header">
<a href="{{ $url }}">
{{ $slot }}
</a>
</td>
</tr>
Then in message.blade I have something like this:
#slot('header')
#component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }}
#endcomponent
#endslot
message.blade is used by all mails, so the same goes for header.blade. The problem is that I want to alter the header text ('app.name' at this moment) in a certain subset of all mails. I'm not sure what the best approach is.
I would like to have something like this:
#slot('header')
#component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }} {{ $optionalVariable }}
#endcomponent
#endslot
Where this $optionalVariable is only set in certain emails and not in others. How can I achieve this?
Maybe wrap it in
#isset($optionalVariable)
{{ $optionalVariable }}
#endisset
I'm following the basic quickstart with laravel 5. I'm deviating only in that I'm using TwigBridge to allow me to use twig templates instead of blade. I'm getting in error when I tried to load my view.
Unknown "method_field" function in "/home/vagrant/laravel-test/resources/views/tasks.twig" at line 63.
method_field should be an available default helper function in laravel. I'm not really sure why twigbridge isn't finding it. Is there something I'm missing I need to make this function available to TwigBridge?
Edit
Here's my code:
{% if tasks|length > 0 %}
<div class="panel panel-default">
<div class="panel-heading">
Current Tasks
</div>
<div class="panel-body">
<table class="table table-striped task-table">
<!-- Table Headings -->
<thead>
<th>Task</th>
<th> </th>
</thead>
<!-- Table Body -->
<tbody>
{% for task in tasks %}
<tr>
<!-- Task Name -->
<td class="table-text">
<div>{{ task.name }}</div>
</td>
<td>
<form action="{{ url('task/'~task.id) }}" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button>Delete Task</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
Edit 2
I partially figured it out. I had to add method_field to the config/twigbridge.php file in the functions array:
'functions' => [
'elixir',
'head',
'last',
'method_field',
].
This got it to run the function, however the output is converted to html entities because it actually renders the input tag text instead of the tag itself. So I need to figure out away to make it not escape the output.
The answer is that you have to add the function to the config/twigbridge.php with an is_safe option. That can be done this way:
in /app/config/twigbridge.php
'functions' => [
// Other functions
'method_field' => [
'is_safe' => [true],
],
],
I have problem with displayin one picture in my home page.
Currently, I loaded some photos. I created a column in the database 'thumbnail'. Wants to do so, to load the photo - thumbnail where the column 'thumbnail
have record = 1.
My Homecontroller:
public function getHome(){
return View::make('pages.home')
->with('offers', Offer::take(8)->orderBy('created_at', 'DESC')->get());
}
my view:
#foreach($offers as $offer)
<div class="col-sm-3" style="border: 1px solid #AADFFF; height:350px; ">
#foreach($offer->photosofoffers as $photosofoffer)
<a href="{{ route('pages.view', $offer->id) }}">
<!--<a href="/pages/view/{{ $offer->id }}">-->
{{ HTML::image($photosofoffer->file, $photosofoffer->title, array( 'class'=>'feature', 'width'=>'240', 'height'=>'127')) }}
</a>
#endforeach
<h3><a href="{{ route('pages.view', $offer->id) }}">{{ $offer->title }}</h3>
<p> {{ $offer->description }} </p>
<h5>Availability: <span class="{{ Availability::displayClass($offer->availability) }}">
{{ Availability::display($offer->availability) }}
</span>
</h5>
<p>Cena <span>{{ $offer->price }}</span>
</p>
#endforeach
Where should I add something?
At the moment loads all the images of the announcement. He wants to load one image, where the 'thumbnail' = 1.
You can eager load the relations and apply a constraint. Something like:
Offer::with(array('photosofoffers' => function($q) {
$q->where('thumbnail', 1)->take(1);
}))->take(8)->orderBy('created_at', 'DESC')->get();
http://laravel.com/docs/5.0/eloquent
If you want to load only those offers that have a photo/thumbnail
Offer::with('photosoffers')->whereHas('photosofoffers', function($q) {
$q->where('thumbnail', 1)->take(1);
})->take(8)->orderBy('created_at', 'DESC')->get();
I am a bit of a newbie to both PHP and Laravel and I trying to build simple Web Apps in order to familiarize myself with both PHP and Laravel. I am getting an undefined variable in blade file. It would be appreciated if someone could help me clear this up.
Basically, what I want to happen is:
I have a View called dashboard.blade.php and in this view there is a text field and button. When the room number is entered and the button is clicked, the room number must get saved in the database and the current view needs to get refreshed but this time, the new room has to be shown at the top. The room gets saved in the database without a problem, but when I try to retrieve it using the foreach loop, I get the 'undefined variable rooms' error
I am using Laravel 5.2
The button concerned with firing off this action (in dashboard.blade.php)
<form action="{{ route('viewroom') }}" method="POST"> //route is viewroom
Please Insert The New Room Number<br>
<input type="text" name="roomid"/>
<button type="submit">Add New Room</button>
<input type="hidden" value="{{ Session::token() }}" name="_token"/>
</form>
Route file
Route::post('/dashboard',[
'uses' => 'RoomController#InsertRoom',
'as' => 'viewroom'
]);
Function used in the RoomController
public function InsertRoom(Request $request){
$this->validate($request, [
'roomid' => 'required | numeric | unique:insert_rooms',
]);
$room = new InsertRoom();
$room->roomid = $request['roomid'];
$room->status = 0;
$room->save();
$rooms = InsertRoom::all();
$request->session()->flash('alert-success', 'Room was successful added!');
return view('dashboard', ['rooms' => $rooms]);
}
In dashboard.blade.php:
<div class="border1">
#if(isset($results))
#foreach($rooms as $room)
$room->roomid
#endforeach
#endif
</div>
Any and all help would be appreciated. Thank you
UPDATE
I forgot to clarify that, I got the error 'undefined variable $rooms' BEFORE I used an if condition to check if $errors was set. After I used if(isset($errors)) I didnt get the error anymore but the information I wanted to show up didn't show up
UPDATE 2
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dashboard</title>
<style>
h1{
text-align: center;
}
.border1{
border: dotted;
border-color: red;
text-align: center;
padding: 20px;
}
.ulerror{
text-align: center;
color: red;
}
.flash-message{
text-align: center;
font-weight: bolder;
color: lawngreen;
}
ul li{
font-family: "Lucida Console";
font-size: 24px;
list-style: none;
padding: 10px;
}
a{
padding: 8px;
}
</style>
</head>
<body>
<h1>Dashboard</h1>
<div class="border1">
#if(isset($rooms))
{{--{{ dd(isset($rooms)) }}--}}
#foreach($rooms as $room)
{{ $room->roomid }}
#endforeach
#endif
{{--1 IGNORE THIS--}}
</div>
<br><br><br>
<div class="border1">
<b>Insert a new Room</b>
<br><br>
<form action="{{ route('viewroom') }}" method="POST">
Please Insert The New Room Number<br>
<input type="text" name="roomid"/>
<button type="submit">Add New Room</button>
<input type="hidden" value="{{ Session::token() }}" name="_token"/>
</form>
</div>
<div class="flash-message">
#foreach (['danger', 'warning', 'success', 'info'] as $msg)
#if(Session::has('alert-' . $msg))
<p class="alert alert-{{ $msg }}">{{ Session::get('alert-' . $msg) }} ×</p>
#endif
#endforeach
</div> {{--flash message--}}
#if(count($errors) > 0)
<div class="ulerror">
<ul>
#foreach($errors->all() as $error)
{{ $error }}
#endforeach
</ul>
</div> {{--error handling--}}
#endif
You should try
<div class="border1">
#if(isset($rooms))
#foreach($rooms as $room)
{{$room->roomid}}
#endforeach
#endif
Typo Error: rooms instead of results. You haven't passed any variable named 'results' from your controller to view.
You just need to check if result object(rooms) is set or not. You can use any of below to do this.
All will return boolean result true or false.
#if($rooms)
#foreach($rooms as $room)
{{$room->roomid}}
#endforeach
#endif
OR
#if(!empty($rooms))
#foreach($rooms as $room)
{{$room->roomid}}
#endforeach
#endif
OR
#if(isset($rooms))
#foreach($rooms as $room)
{{$room->roomid}}
#endforeach
#endif
Instead of doing this:
return view('dashboard', ['rooms' => $rooms]);
Just print out all your rooms in your get view function. And then in your insertRooms function do a:
return redirect()->back();
Instead then your get view will automatically print out the new values because of a page refresh :-)
And please start using the compact method to return variables to your views, i has been best practice sine laravel 5.1 :-)
Also i would advice you to watch some videos on nameing conventions. Best of luck!