Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
2 votes
1 answer
61 views

ckEditor and line breaks

Here's something about line breaks I don't understand. I've recently upgraded from Redactor to ckEditor on a project that accepts public submissions to a job board. These jobs are almost always copy/...
Mosswalker's user avatar
1 vote
1 answer
30 views

Add number variable to template with prefix, suffix and currency

I have added a number field with prefix, suffix and currency symbol: How can I add a variable to a template which shows the number with prefix, suffix and currency? I tried the following which didn't ...
flip's user avatar
  • 149
0 votes
0 answers
17 views

Duplicated queries when using relations and assets

I have this setup: {% for entry in craft.entries().section('mySection').with(['relation.image']).all() {% set relation = entry.relation.one() %} {% set image = relation.image.one() %} {{ entry....
supazu's user avatar
  • 526
3 votes
2 answers
73 views

Unable to find custom template when using a console controller inside a module

I'm creating my first module. Inside this module, I check a few entries for some conditions, and if all conditions are met, I want to send out a personal email. Everything worked, but I wanted to ...
Arno Ramon's user avatar
1 vote
1 answer
32 views

Can't use matrix.one() and matrix.all() at the same page

i try to get blockMatrix value with different way(.one() & .all()) in the same page (this page consists of several templates) but the result is weird. Here how i do it: i have a blockMatrix("...
Nixxian365's user avatar
0 votes
0 answers
28 views

Any way to manually validate a CSRF token on the front-end?

I'm looking to manually validate a CSRF token (passed via GET) in a template, basically as a way of rate-limiting bots accessing a page which generates a CSV file. Poking around the Craft docs and ...
Derek Hogue's user avatar
0 votes
0 answers
20 views

Change layout of relations field in cp "Unable to find the template"

I've created a custom module that adds form submissions as relations to the entry they were submitted on. This functionality works, but I can't figure out how to change the template for the relations ...
Jane's user avatar
  • 11
1 vote
1 answer
66 views

Problem with loop.last

In Dev mode I get the following runtime error: Key "last" for array with keys "parent, index0, index, first" does not exist and it highlights the line {{ not loop.last ? ' & ' ...
Paul Frost's user avatar
  • 1,060
0 votes
0 answers
42 views

twig how to include a twig in an existing div

My project now contain many twig and vue file, and I want to add a footer in every page. Every twig file will {% extends '_base/index.twig' %} so I want to include footer.twig in index.twig so that ...
LJ27's user avatar
  • 1
1 vote
2 answers
31 views

Range filter doesn't accept variables

How do I pass variables into the range filter from a static supertable field? {% for item in variants.b2bProductQty %} {% set start = item.selectRange.cellStartInteger %} {% set end = item....
KSPR's user avatar
  • 3,786
1 vote
1 answer
45 views

twig: loop and switch within set -> dirty code or pragmatic solution

First of all: My solution works ... I can not see any problems. But I'm very unsure whether my code ist a dirty hack or not. Please don't care about details in my code ... I'm uncertain because: There ...
Marc 's user avatar
  • 182
0 votes
0 answers
52 views

Craft 2 - Referencing Twig Variables in Javascript - Variables Do Not Exist

I'm working with a template in Craft 2, and in referencing Twig variables in the Javascript, they are not recognized when the page is previewed. I get a Template Error - Variable x does not exist ...
buck1112's user avatar
  • 400
1 vote
1 answer
94 views

How to extend or override CP template?

I need to add some custom condition to the top siteMenu selector. Template file with top menu: vendor/craftcms/cms/src/templates/_elements/sitemenu.twig Block with this menu: vendor/craftcms/cms/...
DuxaBilii's user avatar
1 vote
1 answer
128 views

Can you create a pop-up in Craft?

Is there a way to create a pop-up for when someone visits the site on the backend of Craft?
Jaci Pieters's user avatar
1 vote
2 answers
123 views

Element In Template Not Hiding On Page Load

I'm working on a template in Craft 2, and I have a number of divs which are part of a Javascript "read more" script, which automatically shortens the visible text at a set number of ...
buck1112's user avatar
  • 400
1 vote
1 answer
41 views

Passing a variable to an include to set an image transform throws Setting Unknown Property error

I'm using an entry field to set an image transform handle: {% set format = block.imageCrop %} Then I'm trying to pass that to an include: {% include 'partials/_img' with { format: format } %} This ...
artmem's user avatar
  • 1,022
1 vote
2 answers
229 views

Make external links open in new tab, while internal not?

I've been going around in circles wondering which way to tackle this, so thought I'd ask while trying things out in case there's a really obvious way staring me in the face! I have tens of thousands ...
Emma Swann's user avatar
1 vote
1 answer
197 views

Twig Runtime Error on Craft 4 Getting Started Tutorial

I'm working through the 'getting started' tutorial and I've run into an error I can't get passed. I've created the Category Group: 'Topics' and then created the Field 'PostCategories' and connected it ...
GeordieJS's user avatar
1 vote
1 answer
170 views

Create deep copy of twig variable

I'm building a filter page with Craft and Sprig. The goal is to show the amount of products for each filter. So for example if we want to filter on color we show 2 checkboxes "Red" and "...
Matthias's user avatar
  • 301
1 vote
2 answers
114 views

Twig > for looping on objects -> only one result

Sorry per advance for my english :/ I am trying to construct an twig array in a .twig file like this : {% set allergenesArray = [] %} {% for allergne in recipe.allergenes %} {% set ...
Nicolas's user avatar
  • 21
2 votes
4 answers
74 views

Find all entries containing a certain twig component

How can I get all the pages (entry urls) which are containing a certain .twig component? Ex: $entries = Entry::find()->search('button.twig')->all(); $urls = []; foreach ($entries as $entry) { ...
Brecht Cloetens's user avatar
0 votes
0 answers
39 views

How to list categories only related to enabled entries or disabled child entries

Edit: solved in comments My entries are set up as a parent > child structure. A single entry can either have children or not have any. If parent has children, the children entries are put in a ...
Jake's user avatar
  • 43
1 vote
1 answer
86 views

I'm trying to remove transforms if my image is an svg? Any tips or advice would be great

{% for icon in icons %} {% set image = icon.icon.one() ?? null %} {% if image %} <div class="c c-md-6 c-lg-6"> ...
Han's user avatar
  • 13
1 vote
2 answers
88 views

Applying custom CSS to a page based on custom ID or class

I want to apply custom CSS to 1 page and am wondering if there is an easy way to do either of the following: -add some code to the Craft Template file that has the opening tag that can add an ID ...
Andy's user avatar
  • 11
2 votes
2 answers
119 views

How to prevent Twig Syntax Error when a plugin is disabled?

I am using the Sprig plugin, and for some reason I'm disabling it in some environments. In config/general.php I have added: 'disabledPlugins' => ['sprig'] And in my twig template, I have a ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
38 views

Events with sub-events in a matrix field - display as a calendar (combined with other events)

I'm building a site where the client has courses that run once a week. We'll have several courses and each course will have a matrix with multiple blocks detailing that weeks class. What I want to do ...
CreateSean's user avatar
  • 1,973
1 vote
1 answer
28 views

Matrix Field - Call block that matches block field value

I've got an event entry with each day of the event in a matrix field block. The block has a date field eventDate and I've got it set up so each block has a unique page that display with the date in ...
CreateSean's user avatar
  • 1,973
1 vote
1 answer
57 views

Creating a new SINGLES page presents a PAGE CAN'T BE FOUND or TEMPLATE CAN'T BE FOUND

I'm hoping you can help resolve my issue or point me in the right direction. Sincere apologies if this question has been asked a million times, however I can't seem to find anything specific to this ...
OGW's user avatar
  • 13
2 votes
1 answer
70 views

Variable entry does not exist on blog post

We just installed the CMS and like it very much. On the other hand while following the basic tutorial we seem to get the error "Variable "entry" does not exist." on the most simple ...
Ron Cooper's user avatar
2 votes
1 answer
192 views

How to show entries randomly

I want to show entries (hundreds) for signed-in users randomly, I use this: .order('RAND()') and in the same time make sure to loop over all entries before start showing the entries that have been ...
Mohamed's user avatar
  • 21
0 votes
0 answers
151 views

CP templates are slow to render

My CP pages are taking ~15 sec to load. It seems the bottleneck is in rendering the Twig templates. This slowness also seems to have manifested quickly and it's affecting multiple separate Craft CMS ...
Steven Wenrich's user avatar
1 vote
1 answer
62 views

Tertiary Nav Items breaking Navigation when lightswitch set to zero

I have a navbar built out based on a pages section (structure) that has a field hideFromNav that when set to on hides the item from the nav bar - this is on line 8 of the code below. This works fine ...
CreateSean's user avatar
  • 1,973
1 vote
1 answer
61 views

Update from Craft 3 + Reasons to Craft 4: how to get fields' conditions from template?

I've just updated from Craft 3 to Craft 4. I was previously using the Reasons plugin for CP but also front-end purpose. On front-end, I was printing field layouts and show/hide the fields based on the ...
Romain P.'s user avatar
  • 1,852
3 votes
1 answer
294 views

What does the triple operator ??? do in this case?

I know what the null coalescing operator (??) does. I have an example here with 3 operators and I am unsure what it does? Here is an example that I came across in a script I am trying to debug: {% set ...
BrokenCode's user avatar
1 vote
1 answer
217 views

Changes to twig template take over 20s to propagate

If I make changes to one of my twig templates, it takes over twenty seconds for Craft to reflect the updates on the local site. I'm running Craft locally in DDEV. I tried the debug toolbar but am ...
darkbasic's user avatar
0 votes
2 answers
61 views

How do I only display a list of users that have entries and hide the rest

I want to list users that have created entries in a specific channel. I tried it the Ben Parisak way, but that didn't work out. here's the code that doesn't work (example 1): {% set entryIds = craft....
outline4's user avatar
  • 595
1 vote
1 answer
70 views

Redactor (or Twig?) Issue stripping <R> and <TM> strings

This is a Craft 3.7.x install with Redactor. My client is writing content referencing the proper usage of their trademarks. They'd like their content to state that it's permissible to use "...
Ed Hebert's user avatar
  • 145
2 votes
1 answer
54 views

Create automatic subpage (kind of) for each entry

I really searched this forum for question like this but i was not able to find the answer. Im creating news portal website, where I have blog entries with url like this /blog/SLUG I want for every ...
Mensur Hafizović's user avatar
0 votes
1 answer
237 views

Eager-loading in a page builder built on NEO field

Upon upgrading to Craft 4, I've realized that I should implement eager-loading in quite a few places as suggested by the Blitz caching plugin. Most of these are within our page builder, which is built ...
InanisAtheos's user avatar
0 votes
0 answers
46 views

Trouble with channel URLs and CSS files not pulling through - Craft CMS 4 Multisite

I'm building a multisite on Craft CMS 4 and I'm having trouble with channel URLs. At the moment I'm working locally and then pushing it to the hosting via github. I've created a folder for each site ...
George Bleasdale's user avatar
1 vote
1 answer
33 views

How do you get Craft to generate multi-paragraph text?

In every other CMS I've used there's an option to compose multi-paragraph text in the back end which is then parsed out into P tags in templates. Neither the native text field nor the popular Redactor ...
Tim Murtaugh's user avatar
1 vote
1 answer
52 views

Group/sort by multiple criteria

I have some users: {% set people = craft.users({ groupId: '1', order: 'lastname ASC' }) And two lightswitch fields associated: isLeadership and isActive. This code groups users by ...
4midori's user avatar
  • 656
2 votes
1 answer
146 views

extending the Craft control panel templates are unstyled

First time building a custom control panel dashboard for a module. Template loads ok but is unstyled and not loading JS that the rest of the control panel screens do. {% extends "_layouts/cp"...
Steven Grant's user avatar
  • 1,855
0 votes
0 answers
28 views

How to append the category field data nested inside a section to an input tag?

while clicking the input tag it should display its related entries Based on the category field the data selected in the backend value should get appended to the input tag. When looping through the ...
Reeves Bale Ronny's user avatar
1 vote
2 answers
625 views

Craft 4: How do I get field by handle?

In Craft 2, I used to be able to do this: https://craftcms.com/docs/2.x/templating/craft.fields.html#getfieldbyhandle-handle {% set body = craft.fields.getFieldByHandle('body') %} {{ body.instructions ...
Tchick's user avatar
  • 105
1 vote
1 answer
22 views

Field data as part of external URL call (jsonclient plugin)

It's possible it's the various search terms I'm using but I can't seem to find anything close to what I'm looking for. I am trying to call an external API URL, with keywords from a field, but while I ...
Emma Swann's user avatar
0 votes
2 answers
373 views

How to reuse "functional code" in multiple twig files

I usually load and prepare data before calling a certain include. That data may be loaded in a certain way for different cases, so I cannot add that data preparation code into the include itself. I ...
Álvaro Franz's user avatar
0 votes
1 answer
103 views

Custom Element Index stopped working after Update

So we had an "old" Craft 3.1.* instance that i needed to update. Which is now running on Craft 3.7.20. This instance does have a Module which introduces a new ElementType with its own custom ...
Leonardo's user avatar
  • 471
0 votes
2 answers
85 views

How to trim each string in an array?

I am looking for how to trim each string in an array, in Craft 3. I would like to check if a string is in an array of strings. The array is from a form submission, a checkbox group. For example, there ...
Kota.M's user avatar
  • 423
3 votes
1 answer
1k views

Loop last error getting entries

Craft 4 Key "last" for array with keys "parent, index0, index, first" does not exist. When using {% if loop.last %} Data is there and printing out a menu but cannot seem to get ...
joomkit's user avatar
  • 2,024

1
2 3 4 5
35