Questions tagged [templating]

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

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

Adding entries to the top level scope of a variable in Twig

I have made a frontpage editing system where the user can desk a frontpage, adding news items and other blocks manually. One of the blocks is "Last n news items". I would like this to ...
0
votes
0answers
19 views

getParam not working after update of CDN at server

Recently, my team had tried to set up a CDN for the server since then the craft.request.getParam or craft.app.request.getParam not working anymore at the server, even we had revert back the changes. I ...
1
vote
1answer
32 views

Filtering by lightswitch fields

Bit of an unusual one and sure must be missing something but know if we have a defined lightswitch field we want to filter against it can quite easily be done so like this: {{ craft.products().myField(...
1
vote
1answer
15 views

Is there a way to query for a list of values belonging to a specific field in a queryset?

For instance, if I wanted an array of all the titles belonging to a subset of entries that I wish to query. The way I know how to do this currently is like so: {% set titleList = [] %} {% ...
1
vote
2answers
37 views

Twig template outputting blank page on non-“dev” environment

I've created a base twig template which contains some basic "maintenance mode" logic. This works perfectly as long as the main ENVIRONMENT in the .env file is set as dev, but fails for ...
1
vote
1answer
21 views

localized site - except home, every page gives me a 404

I have a newly published site, where the localization does not work properly. https://www.nomadenschaetze.com/de/ When i switch to english, it shows the right englisch homoepage. Now, when i click ...
2
votes
1answer
33 views

Blitz Cache dynamic button

I have a Blitz Cache but the only bit of dynamic data on the page is a "Follow" button which changes depending on if you're following this entry. Looking at their docs, I don't see a way of ...
1
vote
1answer
72 views

Input and Use Twig Variable in External JS Script Across Different Pages

I have created a _layout.twig file which acts as my base to hold content on the page -> _layout.twig: <!DOCTYPE html> <html lang="{{ craft.app.language }}"> <head> ...
0
votes
0answers
26 views

Tons of Apache TWIG errors on Craft 3 website

I'm only getting these errors on a select few pages of my website after upgrading from Craft 2 to Craft 3: TypeError: Argument 1 passed to craft\web\twig\variables\CraftVariable::entries() must be of ...
1
vote
2answers
26 views

Matrix fields don't load!

I have some matrix fields defined: But when I use the matrix blocks inside of an entry - I don't get all blocks - just the richText ones. I tested it out - just the richtText Matrix blocks will be ...
1
vote
1answer
29 views

Grouping Super Table Results via Twig Multidimensional Array

I'm trying to loop through a Super Table array and group results based on a category ('contribution'). I've gotten pretty far but I'm struggling creating an array in Twig that gives me what I need (I ...
0
votes
0answers
8 views

Adding a specific field to search() parameter that contains an object

I'm currently running a search which contains an object {query:query, subLeft: true, subRight: true} {% set query = craft.request.getParam('q') %} {% set entries = craft.entries.section('example')....
0
votes
0answers
11 views

External GraphQL API support with Twig

I have external GraphQL API's to get data which will be used in Twig Templates. This has nothing to do with Craft data or Craft's content. Is there a way to call GraphQL from Twig template instead of ...
0
votes
0answers
11 views

Recognizing Twig tags in VS code live server

I'm not sure if this is the correct place to ask this, but seeing as I'm developing with Craft I thought I'd give it a try. Does anyone know if it's possible for the Live Server plugin for VS Code to ...
1
vote
2answers
38 views

{{ entry.image.first().url }} won't show image

I am on my first Craft CMS test site. Have some problems showing a simple image. <img src="{{ entry.hero.first().url }}" title="{{ hero.title }}"> I get the title but can't ...
1
vote
1answer
17 views

Null Length Error on Craft Version 3

I am not super fluent in Twig and I inherited a website from a company that built the site in Craft v2. The site was upgraded to version 3 of Craft recently and one of the template pages is throwing ...
1
vote
1answer
24 views

Simple way to create a slideshow with Twig and a for loop?

I have this code, which is basically a loop in a Twig template where I show opinions: <section class="opinions"> <h2 class="opinions__title heading2"> ...
0
votes
0answers
20 views

Similar plugin filter results by section

I currently have the Similar plugin on my system, and I'm looking for similar entries by Category. It's working great, but I'm looking to limit the results to a specific section. {% set ...
1
vote
1answer
22 views

Output of matrix field twice in one template

I have a matrix field with with multiple types. In a template I want to loop through all of the entries of that matrix field as you normally would. However, I also want to access a bit of data from a ...
1
vote
1answer
34 views

Get first X paragraphs, then output the rest

The below is code that works to only show the first paragraph, then show the rest. Is it possible to instead, show the first five or six paragraphs, then show the rest? {# Split paragraphs using a ...
0
votes
0answers
16 views

How can I get the dimensions of a video asset?

The video itself hasn't any dimensions (width and height) within its object. But Craft saves a thumbnail, right? How would I get to the thumbnail to get its width and height? Or is there something ...
1
vote
2answers
20 views

Limiting entries object when using as json_encode

I'm building a JSON array of several thousand entries using the following entries query: {% set services = craft.entries.section('services').asArray().all() %} The problem is there some private info ...
1
vote
1answer
20 views

Calling a setter via craft.app in Twig

apologies if this has been asked, I don’t seem to be able to find the solution. What is the correct way to call craft.app.session.set in a Twig template (or any other setter function for that matter)? ...
1
vote
1answer
27 views

Freeforms Check Submission is true

I'm trying to create a form that adds a cookie so that someone who has submitted the form can see content on the thank you page to protect the download. Currently I've got this: {{ craft.freeform.form(...
1
vote
2answers
33 views

How can I ensure certain items always display at the end of a list?

I have a website where I want to show Power Coat (-PC) options at the end of a list. The data goes into Craft in an unpredictable order, from a third-party service, so I am responsible for organizing ...
1
vote
2answers
23 views

Sort Entries by Value from Dropdown

I have a list of students and can sort them by name, sport, and school. The name and sport portions are easy, I'm grabbing the values without issue. Where I'm struggling is the school value is from a ...
1
vote
1answer
27 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
14 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
31 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
30 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
39 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
12 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
36 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
16 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
21 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
143 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
19 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
29 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
27 views

How to display decimals as fractions?

Is there a twig filter to display decimal values as fractions?
1
vote
1answer
38 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
35 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
23 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
24 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
49 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
47 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
75 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
36 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
39 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
2 3 4 5
31