Questions tagged [templating]

Front-end Twig templates that can Craftily render markup, scripts, and styles.

Filter by
Sorted by
Tagged with
1
vote
1answer
9 views

Where does Craft store HTML Templates?

I have recently been given access to a Craft site's control panel. I need to edit the homepage to add data in the footer. As I didn't create the Craft website, how can I access the HTML I need to add ...
1
vote
1answer
10 views

Asset file permissions issue hyperlane

I am having trouble setting up image volumes correctly in Hyperlane. My best guess is that is has something to do with permissions but I have not been able to find a solution. This is how I have set ...
1
vote
2answers
30 views

Use dropdown field to add a class to the body tag

I have a website where I want to be able to use different background colors on different project pages. The way I want to achieve this is by having a dropdown field in Craft to select from a set of ...
1
vote
1answer
19 views

How to create different template for specific page?

I have added a "newsletter" page under Admin > Entries > Page [New Entry] And the page is opening fine on the url xyz.com/newsletter But I want to assign a different template to this ...
1
vote
1answer
38 views

DRY variable setting across templates (macro for variable?)

I have a need for something like the following: {# Template A #} {# Do X that sets variable x #} {# Do Y that sets variable y #} {# Pass x and y into A include partials #} {# Template B #}...
0
votes
0answers
11 views

Get entries from a specific level (4) of categories, but go back up the levels if there is not enough content

What would be the best way to achieve this in twig logic? All entries are related to categories. These categories could be between 1 -> 4 levels deep. I would like to start at the deepest level and ...
1
vote
1answer
33 views

{% requireLogin %} not working on extended (layout template) files?

Is there a reason {% requireLogin %} is not firing when using in a parent include? if I place {% requireLogin %} inside the main template file and then use this like so: homework.twig {% extends "...
0
votes
0answers
13 views

Building a tab component in a matrix content builder - child matrixes with SuperTable plugin

There are similar questions and answers, but I'm not finding any that are answering my specific questions. I've built a content builder with a matrix in Craftcms like these tutorials have gone over. ...
1
vote
1answer
18 views

How can I replace a newline (in a plain text field) with a comma?

I need to convert a new line in a plain multiline text field in Craft into a comma. My text looks like: 1 Infinite Loop Cupertino, CA and I want to convert it to: 1 Infinite Loop, Cupertino, CA I ...
2
votes
3answers
113 views

How do Twig filters interact with concatenated strings and shorthand “if-else” ( `var ? true : false` ) strings?

If I am outputting content like this: {{ entry.maxWidth|length ? entry.maxWidth ~ 'px' : 'unset' }} ...and I want to apply the |raw filter to the output (nevermind if it makes sense in this case; it'...
1
vote
1answer
13 views

How can I merge a Modified Date and Time in Twig?

I am trying to generate a modified date and time from a combination of content fields and the current date but I am getting stuck and keep hitting errors, so my logic is either not correct or I am ...
1
vote
1answer
19 views

Checking if related entries are live in a for loop and setting a variable based on the results

So I have a section called children and these are related to various other entries include users. I am fetching all the children for the currentUser like so and eager-loading all the other ...
1
vote
1answer
24 views

Showing different field layouts for entries within the same structure

I set up a structure for pages that looks like this: - All Services - Service 1 - Service 1 subpage a - Service 1 subpage b - Service 2 - Service 2 subpage a - Service 2 subpage b ...
1
vote
1answer
21 views

How to display decimals as fractions?

Is there a twig filter to display decimal values as fractions?
1
vote
1answer
28 views

Get field type in templates

I need to get the field type in my templates like I used to do: field.getField.type but that does not seem to be working in Craft 3 anymore. The result is always null. It also seems that the »type« ...
1
vote
1answer
30 views

How to get a list of unique related entries from within a related entries loop

Bear with me as I am not sure the best way to explain this. But to try and summarise... how can I loop through related entries (locations) inside a a related entries loop (exams -> related to the ...
1
vote
1answer
12 views

Images not showing even after bundling them with asset bundle

So I am trying to build a simple plugin for Craft CMS and I am wish to use my assets in the twig template like css, js, images etc. From what I have read and understood from Asset Bundles, I have ...
1
vote
1answer
21 views

How to use assets while building Craft CMS plugins?

I am trying to build a basic plugin, when installed has a single nav bar item, and of course a twig template which shows up on clicking on that navbar item. I have used the basic template to extend ...
1
vote
1answer
13 views

Stuck when grouping entries to get any other parameters like url, id etc

So I am trying to group entries by location and then group entries in this group by weekday. I have this aspect working with the following code: {% set allClasses = craft.entries .section('...
1
vote
1answer
36 views

Problem with Twig group function, group by year

I am trying to apply the group filter so that my year headings appear in DESC order. They are appearing in ASC order instead, and applying |reverse doesn't work. Suggestions? {% set entries = craft....
1
vote
1answer
34 views

Add variable to twig context

I have created an event to transform the entry data before rendering the page so that it's ready to render components in the template. Event::on(View::class, View::EVENT_BEGIN_PAGE, [$this, '...
1
vote
2answers
56 views

How do you modify the entry data before the template is rendered?

I am using a pattern library which expects a different data structure to what is in entry. Is there a way to parse the entry through a transformer class before the template is rendered? Currently I ...
1
vote
1answer
34 views

How to get the previous or next two entries with images and

To expand upon How to get the previous or next two entries I was wondering how I can also add the image and an input from each entry. I have simplified the html-structure in this example but ...
1
vote
1answer
36 views

Homepage template / queries

I might be over-engineering this a bit, but I'm looking for a clean way to set up my homepage, for as few database queries and maintaining a DRY setup. The homepage is: Hero introduction Fields in a ...
1
vote
1answer
21 views

Get all orders which contains a certain product type

In want to print a list of orders: {% set orders = craft.orders.completed(true).limit(null).all() %} Now I want to make a list of orders with only the product.type XYZ. I tried to fabricate ...
0
votes
0answers
56 views

Overwrite template-files

I want to use one template on several Craft websites (different installations, not multi-sites). Is there a way in Craft I can do something like this? I want to update/overwrite the /templates/core/ ...
1
vote
1answer
23 views

link twig template in a tag

I created two twig templates: home.twig and about.twig. in home.twig it's this code: <a href="/about">go to about template</a> and in about.twig it's: <h1>about</h1> when I ...
1
vote
1answer
18 views

Templating data in HTML

I have an Matrix field and I want to extract data in the following HTML structure: <div class="row"> <div><p>text1</p><img src="{{imgurl1}}" /></div> <div&...
1
vote
1answer
11 views

How to build a language switcher that covers entries with custom routes?

I have a site with a structure and various channels, that live inside that structure. I started with the language switcher from https://craftcms.stackexchange.com/a/26347/8325; but that will only ...
0
votes
0answers
10 views

Cached Images falling back to IP

I'm having a strange problem which I'm unsure if it's my hosting or my Craft's config. My images which I have within a Cached template, once the cache expires or sometimes before they go back to the ...
1
vote
2answers
51 views

Correct Limit for Entries with IF statements

I have content on my site that can't be shown in some countries and requires a basic level of geo-targeting, based on the users profile and not by any form of IP geo-targeting. I have set up an ...
1
vote
1answer
20 views

Pushing additional key values without overwriting existing key values in an array

For an existing key in an associative array, I'm trying to push a new value to it without overwriting the existing values in the key. I've tried this: {% set myArray = { myKey: [ 'value1',...
0
votes
0answers
15 views

Craft CMS 2.9.2 template issue

My script looks like <div class="xl-left"> <h5>Rock</h5> <ul class="list-reset filters__list" data-filter-group="type"> {% for category in craft.categories....
2
votes
2answers
76 views

How to get second last url segment

I'm setting up a dynamic thank-you page for all forms added to the site. Client can add forms with freeform to any page and I have set the return url to this: {{ form.renderTag({ class: "w-full ...
1
vote
1answer
69 views

Output Relative URL

I need to output the relative URL for the current page for a GA event label. According to Craft 3 docs, it seems like rootRelativeUrl() as in: {% relative = entry.rootRelativeUrl() %} should do ...
1
vote
1answer
37 views

How to display plain text only from redactor without any line break or format

Is there a way to display plain text only without any line break or format style. I have an input field using the redactor. I want the result to shows plain text without any formatting for this ...
1
vote
1answer
28 views

Trouble finding the correct path to template in custom module and getting the “Unable to find the template” error

I've created a custom module trying to implement new field types. I'm using How to create custom field type in Craft 3 and https://github.com/mmikkel/IncognitoField-Craft3 as reference on how to ...
1
vote
2answers
42 views

Need help with a Twig template error

I am getting the following Twig error and I cannot figure out what is wrong. I'm new to Twig. Twig Syntax Error – Twig\Error\SyntaxError Unexpected "minify" tag (expecting closing tag for the "cache"...
1
vote
1answer
37 views

Impossible to access an attribute on a null variable - on the one() method - all() works!

First question - but I think this is a bug (not my fault). I have entries/pages (a structure) - one parent (product overview) with children (products) I have one category group with categories - ...
1
vote
1answer
33 views

How to loop through a table and set variables based on the existence (or not) of data in those tables?

I am using a table field in Craft (price) limited to one row only, used to manage price setting in different currencies on an entry. The three cols each contain number fields with the handles dkk, ...
0
votes
1answer
37 views

Encoding special characters even with the raw filter due to include

Hey guys i have something odd happening and I don't understand why: The opening of my template i set a variable {% set text = component.textarea ?? null %} Lower in my template i have the following: ...
1
vote
1answer
34 views

Splitting a Twig Variable into 2 Variables

I want to split my variable into two new variables before and after the dash character "-". How do I adjust my code below to enable this to happen? {% set name = 'first-last' %} {% set firstNameSlug ...
1
vote
1answer
23 views

Slow Category Loading

I have the following category https://www.ticketstoday.co.uk/theatre which has around 600/700 Entries, this is paginated at 30x Entries a page. Unfortunately, it's loading rather slowly. It's not a ...
1
vote
1answer
44 views

Use Craft globals for CSS styles

Is it possible to pass a value from Craft global setting into a CSS/SCSS file? So for example I want to be able to allow the end user to customise colours and fonts without having to include it inline....
1
vote
1answer
43 views

Empty Date Field

I currently have an empty date field, it's unset in the field. I know from reading this becomes "Today's Date" but for some reason the following code is just not working when testing for empty? Unsure ...
1
vote
1answer
19 views

Multiple Asset Field Query

I'm looking to see if there's a better way of querying multiple asset fields in one query, surely there is but I just can't seem to find it in the docs. {% for asset in entry.eventMediaTile....
1
vote
1answer
21 views

Get Random Set of Entries

I'm trying to create a "Hack Job" version of Similar Entries, I'm using the following code but it seems to be getting the same entries over and over again. I know shuffle function does this, but I ...
1
vote
2answers
45 views

List authors on front end by total number of entries

I need to output a list of channel authors. There are about 40 authors but I want the 8 authors with the most entries. Not sure how to achieve this. What I have so far: {# get all the itbuzz ...
1
vote
1answer
29 views

Least CPU intensive way to get number of matching elements?

Which is the least CPU intensive (SQL-intensive) way to get the sum of products that are relatedTo a category? Like this? {% set productCount = craft.products.relatedTo(category)|length %}
0
votes
0answers
40 views

Intermittent internal server error

I'm experiencing a very intermittent internal server error on a Craft site running 3.3.7. The message "An internal server error occurred" appears every now and then when trying to load a page. The ...

1
2 3 4 5
31