Questions tagged [templating]

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

Filter by
Sorted by
Tagged with
0 votes
1 answer
14 views

How to use twig macro inside controller?

I want to use the macro I defined in twig inside a controller or a module. Is that possible?
user avatar
  • 53
0 votes
2 answers
18 views

Get section handle of an entry inside of an EntryField

Maybe Craft 4 is playing games with me but im stuck on this problem: linkedEntry is an entry field which is limited to 1 entry. This outputs the section handle correctly {% set linkedEntry = ...
user avatar
  • 369
1 vote
1 answer
25 views

Do I have to check if a field has a value if I want to use it in an include that already checks the value?

Let's say I have a channel called testimonial which has a field called customerImage. I want to use a twig template to display information about the customer, which may or may not have an image set. ...
user avatar
0 votes
1 answer
27 views

Debugging slow loading entries with matrix field in Control Panel

From a recently migrated Craft CMS 2 site, there are various entries in the Control Panel which take a very long time to load (sometimes over 30 seconds). This is the same in our production ...
user avatar
  • 1,031
1 vote
1 answer
35 views

How to implement Laravel's collection `filter` method inside twig?

How to implement Laravel's collection filter method inside twig? Laravel: $collection = collect([1, 2, 3, 4]); $filtered = $collection->filter(function ($value, $key) { return $value > 2; }...
user avatar
  • 53
1 vote
1 answer
27 views

Get all entries by structureId

It is possible to get all entries by structureId ? If yes how ? For now i use something like this: {% if entry.parent %} {% set relatedEntries = entry.parent.children()|filter(v => v.type == '...
user avatar
  • 53
1 vote
2 answers
25 views

Translate only the default twig value (Nesting twig filters)

Is it possible to write this as a one-liner? {% if craft.entries.section('mypage').one() != null %} {{ craft.entries.section('mypage').one().title }} {# If title is provided - use, but don't ...
user avatar
  • 147
1 vote
1 answer
30 views

How can I output only half the entries in a loop?

I'm building a Craft website on Bootstrap 5. I want to split the output of a loop evenly across 2 seperate columns. There is an image column in the middle so the loop can't be continuos. The amount of ...
user avatar
3 votes
1 answer
52 views

.all() — Looping through element queries directly has been deprecated

This is very nearly a duplicate question but I can't figure out where to insert .all() to execute my element query. I'm still asking because I may be messing up php, function or filter syntax ...
user avatar
  • 65
2 votes
1 answer
49 views

Craft Commerce: Multiple redirect submit buttons from cart form (checkout/update cart) without ajax

I'm building a basic cart page in Craft 3.7.37 with Commerce 3.4.12. The /store/cart page has a <form> with the line items in the cart next to an <input /> to change quantity and one to ...
user avatar
  • 65
2 votes
1 answer
45 views

Disable template cache globally based on condition

I'm looking for a way to disable the template cache ({% cache %} tags) for the entire request based on a specific condition (not just based on the current environment). In this case, the condition is ...
user avatar
  • 6,775
1 vote
2 answers
38 views

Construct entries object from an array of IDs

I have 2 arrays of entry ID's that I need to merge and generate an entries object that I can iterate through and paginate. The reason for doing it this way at all, is that I need to display entries ...
user avatar
2 votes
1 answer
59 views

Can I change a user field with twig without using a form?

I basically just want to set the value of a users field to a different number if something happens, so that the user field is actually updated in the CMS. Can I do that without creating a form? So ...
user avatar
1 vote
1 answer
154 views

Twig in array not working as expected

I am trying to get an entry type check on an array {% set landerArray = ['fundingLander','healthLander', 'projectLander', 'publicationLander'] %} {% set pageType = entry.type %} {% if ...
user avatar
  • 1,900
1 vote
1 answer
51 views

Uppercase certain words in string

We have some content that contains words that should be presented in uppercase - the content comes via an API and is in all uppercase, we change it to title case to make it presentable. I had started ...
user avatar
  • 107
1 vote
1 answer
30 views

Hack into .getUrl() method of an entry

Due to some SEO and infrastructure issues I would like to be able to intercept the getUrl() method of entries and modify its return value. e.g. <a href="{{ entry.getUrl() }}">{{ entry....
user avatar
0 votes
0 answers
41 views

'Endless Loop' Kiosk Crashing Randomly - Craft 2

I am needing an 'endless loop' through my entries for a kiosk application, and was wondering if this approach would work for that? I had been using just Twig on a template, cycling through my selected ...
user avatar
  • 380
0 votes
0 answers
35 views

"Missing template" when omitting file extensions (.html.twig) or underscore

I'd like to be able to only have to refer to a file by it's name, just like it works in JS (e.g. import './js/scripts') and SCSS (e.g. @import './variables'), without the need for file extensions or ...
user avatar
2 votes
1 answer
158 views

Debugging with dump()/dd() within Twig templates

This feels like it falls under silly/obvious questions, but I can't seem to find a decent answer anywhere, so I'm asking here: How do I find out which methods for example, is available on an object? ...
user avatar
0 votes
1 answer
26 views

Get the localized handle and slug for "current" section for constructing breadcrumbs

I'm trying to contruct breadcrumbs for entries under a specific section. This feels like such a "how-hard-could-it-possibly-be" type of question, but I've been at this for a lot more time ...
user avatar
1 vote
1 answer
90 views

Checking for a valid date in a query string parameter using Twig

I have a form that lets you search articles by date. The 'Results' template uses dates from the query string in an Entries Query like this: {% set afterParam = craft.app.request.getQueryParam('after') ...
user avatar
2 votes
2 answers
145 views

PHP array missing attributes when converted to JSON

I am converting certain php data to json for use in my front end javascript. I have an array of product variants, an array of images from a media field that is defined on my variants, and an array of ...
user avatar
1 vote
1 answer
31 views

How can I use the final URI segment as an argument without losing the entry variable?

I have a Structure - Products - that contains multiple products, and each product contains different sub pages (details, pricing, etc). One section of the Structure is Details which is under each ...
user avatar
0 votes
0 answers
23 views

Craft 2 Manually Rendered Template - Logic

I'm currently working on a plugin in Craft 2 that will load entries into Ajax and then output to a template, one entry at a time, controlled perhaps by javascript window.setTimeout to advance to the ...
user avatar
  • 380
1 vote
1 answer
29 views

Table Field Row ID?

I need a unique id for each table row. Something like this which does not work: {% for row in block.buttons %}{{ row.id }}{% endfor %} Is this possible? Thanks!
user avatar
  • 183
1 vote
1 answer
158 views

How to create custom utility/helper functions for use in Twig templates?

So when using Drupal or Wordpress -- obviously you can write as much PHP in a template as you need, or in Wordpress for example, you can abstract that functionality away to the functions.php file. ...
user avatar
1 vote
2 answers
84 views

Showing URL in 'clean' way, omitting 'https://', 'www' and '/'

Is there a way to dispay URLs as a 'clean URL' within Twig? I want to omit 'https' (or 'http'), 'www.' and the '/' at the end for URLS I want to display in the front-end. Input: https://www....
user avatar
  • 55
1 vote
1 answer
39 views

Get parent entry from child entry where relationship is in parent matrix field

I have a parent entry with a matrix field and one of the blocks has a relationship to a child entry. How do I access the parent entry from the child entry page? tried this, where eddChapter is the ...
user avatar
  • 1,907
1 vote
1 answer
82 views

Is it possible to access a Craft service directly from a Twig template?

Before attempting to perform an asset transform to an AVIF or WEBP format, I'd like to use Craft's Images service to determine if the server actually supports either of those formats like so: <...
user avatar
  • 133
1 vote
0 answers
24 views

Craft 2 - Date Comparison In Criteria - Impossible to access an attribute ("today") on a string variable (">=")

I am working with a template in Craft 2, and I am setting up the criteria for entries to be displayed. Here is my code (below). {% set today = now|date('Y-m-d') %} {% set criteria = { section: '...
user avatar
  • 380
0 votes
0 answers
31 views

ImagerX Connection Refused on Craft Nitro

I've currently got a website setup with Craft Nitro, though when trying to query an ImagerX image I get the following error: cURL error “7” encountered while attempting to download “http://xxxxx....
user avatar
  • 1,230
1 vote
1 answer
50 views

Asset Custom Field Returning Null in Array

I am relatively new to Craft CMS and I have encountered an issue that I have attempted to debug for quite some time. When using the {% dd %} function to dump my array, a load of my custom fields ...
user avatar
1 vote
1 answer
29 views

Bad Gateway when using cached category query

I'm trying to find all tiers that have associated entries for a selection dropdown. This does not work, and throws a 502 error {% set allTeirs = craft.categories.group('catPartnerTeirs') %} {% set ...
user avatar
1 vote
1 answer
75 views

How to find next sibling from entry order of parent entries field

I have an index of projects that uses a standard entries field to select multiple entries to display and also provides a custom order (different to their Structure order). This is my "Projects&...
user avatar
1 vote
1 answer
38 views

Replace HTML string in body tag?

I have thousands of imported entries which have HTML image embeds to files which no longer exist. Is there a way to use the replace function in the tag to say replace <img src="[variable ...
user avatar
-1 votes
1 answer
76 views

how to create a custom plugin if the user enables plugin settings then it will replace the website home page to my custom design? [duplicate]

I am trying to create a plugin if the user enables plugin settings then it will replace the homepage of the website with my custom designed template
user avatar
  • 23
1 vote
1 answer
48 views

For loop to dynamically output field names

I have a set of fields: fieldName1 fieldName2 fieldName3 fieldName4 fieldName5 and I want to be able to create a for loop something like this: {% for i in 1..5 %} {% if entry.fieldName ~ i|length ...
user avatar
  • 509
3 votes
1 answer
94 views

Is there a way to return all available (custom) variables in some kind of list?

As I'm still a total n00b in working with CraftCMS, so I hope to get some help from more experienced users :-) I followed every available tutorial (which are very clear and well written. Great job!) ...
user avatar
  • 61
1 vote
1 answer
65 views

How to Create an Author Page?

I'm trying to understand the best or most common approach to creating unique author/user pages that list that user's blog entries. This question was helpful for how to process the results. However, I'...
user avatar
0 votes
1 answer
111 views

Want to use assets field my template settings in custom plugin craftcms

I am creating a plugin that is based on images the admin will upload some sort of images in plugin settings not sure how to creat image field setting in plugin
user avatar
  • 23
1 vote
1 answer
59 views

Twig filter country_name in craft CMS

Craft CMS doesn't have TWIG filter country_name. Even by default country name filter package is not available in twig. We need to install the corresponding package. https://twig.symfony.com/doc/3.x/...
user avatar
1 vote
1 answer
112 views

Upgrading to 3.7.26 causes tempnam() error from twig's FilesystemCache.php

I am upgrading a Craft project that I have been neglecting for a little bit too long. I am upgrading to 3.7.26 from 3.4.25; on top of this, I am upgrading from PHP 7.1 to PHP 7.4. I'm also updating a ...
user avatar
1 vote
1 answer
114 views

Using UrlHelper from template or remove query string params when paginating?

I have an implementation of a pagination which uses fetch() to get a subset of the page (i.e the page listing and pagination links), so when switching pages it gets the new list, as well as the ...
user avatar
  • 213
0 votes
0 answers
18 views

Custom GraphQL Resolver that utilizes the same craft function used in twig

I'm pretty new to Craft CMS or PHP for that matter. I have custom code that unfortunately can't be done with just GraphQL so I need to utilize the same functions used in a twig template, in a custom ...
user avatar
1 vote
1 answer
30 views

Craft 3 paginate not working when fetched with a controller

I'm loading a paginate via Craft::$app->getView()->renderTemplate(), this is being executed within a controller. But my pageInfo.nextUrl is now the url of my controller (/actions/controllername/...
user avatar
  • 160
0 votes
0 answers
17 views

Entry Looping Template With Javascript and 500 Internal Server Error

I'm working with a looping mechanism in my Twig code that loops through entries and displays them for a kiosk type of application. The loop itself works for the most part, although after a few hrs, it ...
user avatar
  • 380
1 vote
1 answer
27 views

Find attributes in an object

I have a craft project which I've inherited and I'm trying to make some minor changes. I don't know PHP, Craft, or Twig very well so forgive me if this is an XY problem. This website is a company ...
user avatar
1 vote
1 answer
69 views

Customizing Field Layout / UI element in Craft Control Panel

Maybe I don't understand well the usage of UI Element in Field Layout, but I would like to display something more 'jazzy' for the admin on his CP and I thought inserting a twig template in the page ...
user avatar
1 vote
1 answer
134 views

Remove red error lines in VS code for TWIG

I've come across this a few times in my code / and others. Basically - there is no error, this is valid syntax and works, but is there a way I can highlight this and tell VS code - this is ok, dont ...
user avatar
  • 289
1 vote
1 answer
23 views

how to write db-commands on custom table (PHP syntax) inside twig file?

if i have a custom table (ct_table) and i have to use MySQLi commands on it using the PHP syntax, it won't work if i put the PHP snippets inside a twig file. So are there any tools or official methods ...
user avatar
  • 125

1
2 3 4 5
34