I would like to check if is last post from loop. I am using pyroCMS. But problem is that if i am using helper:count two times it is not working correctly. How can i assign helper:count to variable and use later variable. Is this possible?
{{ blog:posts limit="5" order-by="title" order-dir="desc" }}
{{ if { helper:count mode="subtract" } == blog:all_posts}}
<li>
<a href="{{ url }}" title="Read more about: {{ title }}">
<span class="naslovna_datum_novice">{{ helper:date format="d.m.Y" timestamp=created_on }} - </span>
{{ title }}
</a>
</li>
{{ elseif { helper:count mode="subtract" } == 5 }}
<li>
<a href="{{ url }}" title="Read more about: {{ title }}">
<span class="naslovna_datum_novice">{{ helper:date format="d.m.Y" timestamp=created_on }} - </span>
{{ title }}
</a>
</li>
{{ else }}
<li class="pikce_spodaj">
<p>
<a href="{{ url }}" title="Read more about: {{ title }}">
<span class="naslovna_datum_novice">{{ helper:date format="d.m.Y" timestamp=created_on }} - </span>
{{ title }}
</a>
</p>
</li>
{{ endif }}
{{ /blog:posts }}
So how to assign {{ helper:count mode="subtract" }} to variable?? How to assign anything to variable?
There's actually a simpler way; the streams core code adds a last property to the final item in an array - source code - that you can just query with a conditional:
{{ if last }} foo {{ endif }}
(The source code that does that is
Here's a working example for blogs I've just tested:
{{ blog:posts limit="5" order_by="title" }}
<h2>{{ title }}</h2>
[...]
{{ if last }}<p>This is the last item</p>{{ endif }}
{{ /blog:posts }}
Also, as Nick points out, you can have more than one counter.
Related
I overrided my form in EasyAdmin to organize differently my input so I did like this :
In my Crud :
public function configureCrud(Crud $crud): Crud
{
return $crud
->setPageTitle(Crud::PAGE_INDEX, 'admin.menu.infos')
->setFormThemes(['bundles/EasyAdminBundle/crud/company/edit.html.twig'])
;
}
And in my Twig :
{% extends '#EasyAdmin/crud/form_theme.html.twig' %}
{% use '#EasyAdmin/symfony-form-themes/bootstrap_5_layout.html.twig' %}
{% block form %}
{{ form_start(form) }}
<div class="row">
{{ form_row(form.logo) }}
{{ form_row(form.phone) }}
{{ form_row(form.catchphrase) }}
</div>
<div class="row">
{{ form_row(form.businessName) }}
{{ form_row(form.email) }}
{{ form_row(form.website) }}
</div>
<div class="row">
{{ form_row(form.companyName) }}
{{ form_row(form.address) }}
{{ form_row(form.linkedin) }}
</div>
<div class="row">
{{ form_row(form.siren) }}
{{ form_row(form.zipcode) }}
{{ form_row(form.facebook) }}
</div>
<div class="row">
{{ form_row(form.legalForm) }}
{{ form_row(form.city) }}
{{ form_row(form.twitter) }}
</div>
<div class="row">
{{ form_row(form.description) }}
</div>
{{ form_end(form) }}
{% endblock %}
The form is like I wanted and when I submit, it's work but the problem is when I make an error. For example if I valid with an empty value, then instead of getting my form_errors, I've got a 500.
I've tried different things but none of them worked :
block errors :
{{ form_start(form) }}
{% block form_errors %}
{{ parent() }}
{% endblock %}
individual error :
{{ form_errors(form.businessName) }}
Any idea ?
I have a Blade component called persons, that has different slots I'd like to fill.
<div class="person">
<img src="{{ $image_url }}" alt="{{ $image_alt }}">
{{ $name }}
{{ $information }}
<a class="button button-primary" href="{{ $link }}" target="_blank">Homepage</a>
</div>
And I have various template files, where I'm doing a foreach and I'd like to use the persons component to show the info.
#if ($persons)
#foreach ($persons as $person)
#component('components.person')
#slot('image_url')
{{ $person['person_image'] }}
#endslot
#slot('name')
{{ $person['person_name'] }}
#endslot
#slot('information')
{!! $person['person_information'] !!}
#endslot
#slot('link')
{{ $person['person_link'] }}
#endslot
#endcomponent
#endforeach
#endif
Sometimes some fields might be empty. For example, sometimes somebody doesn't have an image or a homepage and in that case I'd wouldn't want to show that empty field on the homepage.
Logic says that I should add issset() or empty() into my component file, like this:
<div class="person">
#empty ($image_url)
<img src="{{ $image_url }}" alt="{{ $image_alt }}">
#endempty
#isset ($name)
{{ $name }}
#endisset
#isset ($information)
{{ $information }}
#endisset
#isset ($link)
<a class="button button-primary" href="{{ $link }}" target="_blank">Homepage</a>
#endisset
</div>
But this doesn't seem to work at all. It either removes everything or nothing at all ( depending on if using #isset() or #empty() ).
So my question is: Is it possible to fill component slots conditionally in a foreach loop?
This is from a while ago, but you can use the null coalesce operator to define a default
<div class="person">
<img src="{{ $image_url }}" alt="{{ $image_alt }}">
{{ $name ?? '' }}
{{ $information ?? '' }}
<a class="button button-primary" href="{{ $link }}" target="_blank">Homepage</a>
</div>
Use #if and the null coerce operator and set the default value:
<div class="person">
#if ($image_url ?? null)
<img src="{{ $image_url }}" alt="{{ $image_alt ?? '' }}">
#endif
<span>{{ $name ?? 'No name' }}</span>
{{ $information ?? null }}
#if ($link ?? null)
<a class="button button-primary" href="{{ $link }}" target="_blank">Homepage</a>
#endif
</div>
it is better to check them in the upper level as you said, but notice that you should pass something into slots if they have name slot, so you should call:
#slot('myslot')
#if($myobject->value)
<h5>
Show
</h5>
#endif
#endslot
This works for me.
#isset($qualitycheck)
<a class="dropdown-item p-2" href="{{ $qualitycheck }}">Quantity Check</a>
#endisset
I'm trying to control the rendering of password fields based on whether i'm editing an user or creating one. I'm doing this with a simple session boolean variable as follows:
{{ form_start(userForm) }}
{{ form_errors(userForm) }}
<div id="user-fg-email" class="form-group">
{{ form_label(userForm.email) }}
{{ form_errors(userForm.email) }}
{{ form_widget(userForm.email) }}
</div>
{% if app.session.get('editingUser') == false %}
<div id="user-fg-pp1" class="form-group">
{{ form_label(userForm.plainPassword.first) }}
{{ form_widget(userForm.plainPassword.first) }}
</div>
<div id="user-fg-pp2" class="form-group">
{{ form_label(userForm.plainPassword.second) }}
{{ form_errors(userForm.plainPassword.first) }}
{{ form_widget(userForm.plainPassword.second) }}
</div>
{% endif %}
<div id="user-fg-role" class="form-group">
{{ form_label(userForm.role) }}
{{ form_errors(userForm.role) }}
{{ form_widget(userForm.role) }}
</div>
<button type="submit" class="btn btn-primary pull-right">Submit</button>
{{ form_end(userForm) }}
However when this boolean is evaluated as true, which is supposed to prevent these fields from rendering, they are still being rendered assumingly by the later following form_end tag.
Is there a way to prevent that from happening?
edit:
if editingUser == true the password fields are actually rendered after the button, hence my assumption it's done so by the form_end tag.
Because you have to specify Twig to not display all the rest of the fields which are not explicitly rendered in the form : http://symfony.com/doc/current/reference/forms/twig_reference.html#form-end-view-variables
{{ form_end(form, {'render_rest': false}) }}
In my views folder i have layouts/main.blade.php and under store/index.blade.php i am using the layout file like so:
#extends('layouts.main') // importing here.
#section('promo')
<section id="promo">
<div id="promo-details">
<h1>Today's Deals</h1>
<p>Checkout this section of<br/>
products at a discounted price.</p>
Shop Now
</div><!-- end promo-details -->
{{ HTML::image('img/promo.png' , 'Promotional Ad') }}
</section><!-- promo -->
#stop
#section('content')
<h2>New Products</h2>
<hr>
<div id="products">
#foreach($products as $product)
<div class="product">
<a href="store/view/{{ $product->id }}">
{{ HTML::image($product->image , $product->title , array('class'=>'feature' ,
'width'=>'240' , 'height'=>'127')) }}
</a>
<h3>
<a href="/store/view/{{ $product->id }}">
{{ $product->title }}
</a>
</h3>
<p>
{{ $product->description }}
</p>
<h5>Availability:
<span class="{{ Availability::displayClass($product->availability) }}">
{{ Availability::display($product->availability) }}
</span>
</h5>
<p>
<a href="#" class="cart-btn">
<span class="price">${{ $product->price }}</span>
{{ HTML::image('img/white-cart.gif' , 'Add to Cart') }}
ADD TO CART
</a>
</p>
</div>
#endforeach
</div> <!-- end products -->
#stop
In my storeController , i am calling the store/index.blade.php file like so:
public function getIndex() {
return View::make('store.index')
->with('products' , Product::take(4)->orderBy('created_at' , 'DESC')->get());
}
In my routing file, i have the following:
Route::get('/', array('uses' => 'StoreController#getIndex'));
But still when i load my / , i get some other template rather than layouts/main.blade.php. Why is this happening ? can anybody explain ?
Why is layouts/main.blade.php not loading when i hit / in the browser ?
Thank you.
Alex-z.
Well i had the following syntax .
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
{{ HTML::style('css/bootstrap.css') }}
{{ HTML::style('css/animate.min.css') }}
{{ HTML::style('css/style.css') }}
{{ HTML::style('css/nprogress.css') }}
{{ HTML::style('css/new-arrivals.css') }}
Removing the below line
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
solved my problem ... Why though ? also how do i disable cache in laravel during development ?
I've created a page and then put this code
<section class="cont_pad">
<div class="container_12">
<article class="grid_8">
{{ blog:posts limit="5" offset="5" category="adultos" }}
<section class="post">
{{ if imagen_portada }}
<div class="postimg"><img src="{{ url:site }}files/thumb/{{ imagen_portada.id }}/610/220" class="pic2" alt="{{title}}" title="{{title}}"/></div>
{{ endif }}
<div class="entry-date">
<div class="posttime">
<h3>{{ helper:date timestamp=created_on }}</h3>
</div>
<div class="entry-utility">
{{ asset:image file="blog/icon1.png" }} {{ user:display_name user_id=author_id }}
<br/>
{{ if category }}
<span>{{ asset:image file="blog/icon2.png" }} {{ category:title }}</span>
{{ endif }}
{{ if keywords }}
<span>{{ asset:image file="blog/icon2.png" }} {{ keyword }}</span>
{{ endif }}
</div>
</div>
<div class="entry-text">
<h3 class="posttitle">{{ title }}</h3>
<div class="entry-content">
{{ intro }}
<p>{{ helper:lang line="blog:read_more_label" }}</p>
</div>
</div>
</section>
{{ /blog:posts }}
{{ pagination }}
</article>
<article class="grid_4 last-col">
<aside id="sidebar">
{{ widgets:area slug="widgets_blog_adultos" }}
</aside>
</article>
</div>
</section>
inside to show posts from category "adultos" but I'm not getting nothing. I have one post and it's LIVE in this category. What is wrong? I read Blog Plugin Docs also check the Blog Plugin Code at package "PyroCMS\Core\Modules\Blog\Plugins" and can't find where it fails. Also and related to this same question, can I paginate trough all the posts? I need some help here because I can't find what is wrong
Is the timezone on the computer set up wrong? If PyroCMS thinks the "Publish Date" is in the future it wont show it on the frontend.