Skip to main content

Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
34 views

How in Craft 5 how do I query for related entries that are related from within a matrix field in a matrix field (nested matrix fields)?

In Craft 5 how do I query for related entries that are related from within a matrix field in a matrix field (now entryTypes) (nested matrix fields). I want to show all related models for a product. ...
Terry Upton's user avatar
  • 1,894
1 vote
1 answer
24 views

Config for template path switch

I seem to remember in a multisite Craft 3 setup I could specify the root template path for a site. Is this still possible? I have scoured the Craft 5 docs and can't see it mentioned in the general ...
joomkit's user avatar
  • 2,048
0 votes
2 answers
69 views

Re-using element queries in templates, where and how when using native Cache tags?

I am looking for a bit of support and guidance with caching. Specifically where to place queries, how to re-use them and structure this across a project. So the current project has no caching at all ...
Terry Upton's user avatar
  • 1,894
1 vote
1 answer
19 views

Displaying Images from DO Spaces to Template

Is there a way to recursively call images from a digital ocean spaces bucket folder into a twig template (similar to how locally stored images work)? Or would I have to build a module to do that?
mattalie's user avatar
1 vote
2 answers
104 views

How to create Twig extension in Craft CMS 5

I am new to Craft CMS and Yii2 but I'm experienced with PHP a lot. I'd like to write a custom Twig function (extension) returning a part of a file. For example something like: {{ craft.myplugin....
Martin Ille's user avatar
2 votes
1 answer
471 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
39 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
  • 159
0 votes
0 answers
28 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
92 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
34 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
54 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
21 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
140 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
48 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
35 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
48 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
  • 324
0 votes
0 answers
58 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
137 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
179 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
229 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
54 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
350 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
323 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
242 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
  • 311
1 vote
2 answers
185 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
96 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
41 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
120 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
108 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
159 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,917
1 vote
1 answer
40 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,983
1 vote
1 answer
39 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,983
1 vote
1 answer
84 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
88 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
265 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
180 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
65 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,983
1 vote
1 answer
68 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,917
3 votes
1 answer
308 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
261 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
62 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
268 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
49 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
38 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
53 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
  • 666
2 votes
1 answer
171 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
795 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
2 3 4 5
35