I have the following in a custom text field in a view:
<h5 class="rates_title">{{title}}</h5>
{%if field_car%}
<p class="car">{{field_car}}
{%if title != "Home" %}
<span class="small_caps">car</span>
{%endif%}
</p>
{%else%}
<p class="view-details">View Details</p>
{%endif%}
Everything works except the {%if title != "Home" %} part. Every item gets the span tag, even Home, which I do not want. Yes, the title is Home, and I can confirm that in the <h5> tag.
title at that point is an array and needs to be rendered but then it will contain html tags so you need to search in that rendered string for Home like this
{% if 'Home' in title|render %}
<span class="small_caps">car</span>
{% endif %}
Related
I have a page view that displays title and body fields and the twig template for the view is named as "page--my--view.html.twig". The view content is as follows:
{% if page.content %}
{{ page.content }}
{% endif %}
How can I add individual fields and classes in this template? For example:
<h3 class="title">{{ fields.title.content }} </h3>
I want to add a 'for' loop and print all the titles through page template like above. How to do this?
I have a view named "Blog archive". The view displaye title, blurb and image fields. It's a page view and the twig template for the view is named as "page--blog--archive.html.twig". The view content is as follows:
{% if page.content %}
{{ page.content }}
{% endif %}
Thsi prints out the view fields correctly but without any style classes. I want to add the below snippet into the twig template and iterate through view rows:
<div class="grid-4 omega ft-text">
<h3 class="blog-title">{{ fields.title.content }} </h3>
<br/>
<span style="font-family: sans-serif; font-size: 10pt;">
<p>{{ fields.field_blurb_new.content }}</p>
</span>
<h4>{{fields.field_blog_readmore_link.content }}</h4>
</div>
any help on how to achieve this?
Here's partial template:
<a href="{{ url('videos') }}">
<h6 class="borbottom text-uppercase"><i class="fab fa-youtube"></i> Serke TV</h6>
</a>
{% for p in page.find('/videos').children if p != page %}
<h3>{{ p.title }}</h3>
{% endfor %}
I have videos route, that displays all his child elements. I want to display all videos (child elements) in a block as partial template, which i certain pages.
However that page.find() nor page.collection('videos') not working for me.
You are using page object which is the current page. So you are looking for videos pages in the current page.
You need to use pages object to be able to search in all pages. You can see the functions you can use with this object here
I'm working with a taxonomy term template page in Drupal 8 and I need to be able to show specific content based solely on the taxonomy term that is populating the content of the page. I'm using the taxonomy-term.twig.html template as a starting point, but I'm not having any luck comparing a string value against the {{ name }} variable. Here's the code I have so far:
<section{{ attributes.addClass(classes)}}>
{% if 'general' in name %}
<img class="promo-image" src="http://placehold.it/150x150" alt="promo">
<h3 class="promo-title">Promo title text</h3>
<p class="promo-copy">lorem ipsum dolor set amet</p>
<div class="links">
Learn more
</div>
{% endif %}
</section>
If I output the name variable like normal {{ name }} it prints the tag name onto the page, but I can't figure out how to compare the value against anything. I've tried a straight if equals route as well, but it seems like the name variable is an array.
Since the name variable is an array, and I only needed the first value I added:
{%
set tag = name['#items'].0.value
%}
Then changed the if statement to:
{% if tag == 'text' %}
<section{{ attributes.addClass(classes)}}>
<img class="promo-image" src="http://placehold.it/150x150" alt="promo">
<h3 class="promo-title">Promo title text</h3>
<p class="promo-copy">lorem ipsum dolor set amet</p>
<div class="links">
Learn more
</div>
</section>
{% endif %}
Now the template is working the way I intended.
I want to make a simple blog that shows the details of a post when a user clicks a title in a list of new posts on an index page. However, I realized that my detail of post shows overflow in my block mycontent, this is what I did:
base.html has a line like this:
<div class="col-md-8">
{% block mycontent %}
{% endblock %}
</div>
my read_post.html
{% block mycontent %}
<h3>{{ post.title }}</h3>
<code>{{ post.publish }}</code><br>
{{ post.content|linebreaks }}
{% endblock %}
This is my result when I have long text, I want it to have a newline and to not overflow from block mycontent. I am using boostrap for theme site
Have you tried word-wrap: break-word property?
- Word-wrap allow long words to be able to break and wrap onto the next line
- break-word allows unbreakable words to be broken