Questions tagged [templating]

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

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

Using {% cache %} tags around {% template %} includes (or in Header)

I was wondering if it makes sense to wrap these {% cache %} around {% include %} tags that call a separate file with params. Is it better to just include them in the actual file itself? For example, ...
1
vote
1answer
13 views

Show Category Title only where an entry has been included in an Entries field

I have a Category Group with an Entries field assigned so the admin can select which existing Entries should fall within a given category. An Entry can be assigned to multiple categories. On the ...
1
vote
1answer
20 views

How to check if an entry is enabled for a particular site?

Is there a way to find out if an entry is enabled for a particular site? I know there's the enabledForSite property, but it doesn't look like it accepts any arguments. Ideally I'd like to do ...
1
vote
1answer
20 views

Can I call a dynamically named variable through twig?

I am using Craft 3 with the Commerce 2 plugin. I am trying to dynamically call a variable in a twig template where this variable has to be a "placeholder" for a handle of a field inside a block ...
1
vote
1answer
22 views

What's the easiest way to generate a link to edit a given entry in Craft?

Assuming I am fetching an entry like so: {% set profile = craft.entries.id(8268).one %} What is the easiest way to generate a link that allows you to edit that entry in Craft? I know you can do the ...
1
vote
1answer
21 views

Can't get current entry's ID - Impossible to access an attribute (“id”) on a null variable

I'm trying to upgrade my website to Craft 3 and can't resolve one issue with this piece of code: {% for category in craft.categories.group('blogCategories').order('title') %} <li><a href="...
1
vote
1answer
16 views

List child categories which have entries based on the current categories

I am looking to output the child categories of a parent category. I only need to show the categories which have entries related to them. I have done this to show all categories using {% set entryIds ...
1
vote
1answer
26 views

What is the significance of craft.app.request.segments|last == _self

While reading this blog article about RSS templating, I came across the following twig code if craft.app.request.segments|last == _self I understand that the above command, in general, yields URL ...
1
vote
2answers
30 views

How could I include another template on a click with ajax?

I am a newbie with ajax and I have to display a template only when clicking on a button. This template is weighing and it will be on all pages, so I want to use ajax. Someone can help me?
1
vote
1answer
28 views

Importing Macros doesn't work

I'm trying to upgrade my website to Craft 3, so I've imported all template files and installed the necessary plugins, but I can't deal with one error. I've got a template named _layout.twig, and the ...
0
votes
0answers
5 views

Craft 3 Matrix Field customFields property 'required' and 'sortOrder' fields null

I'm trying to dynamically build a frontend form based on a Matrix field. I'm iterating over the entry.aMatrixField.customFields array which returns me an array of field objects in Twig. The field ...
1
vote
1answer
23 views

Get entries related to selected category only and not it's ancestors

The following is using commerce product entries, but I'm reasonably sure it could be any entry. With the following category taxonomy: - Category 1 - Category 1A - Category 2 - Category 3 ... If ...
1
vote
0answers
15 views

EagerLoading on category pages with different product types

I have a category template like so; {% extends '_layouts/_site' %} {% set products = craft.products .with( [ 'department', 'productImage', 'finish', 'pcd', 'variants', 'thread', '...
1
vote
1answer
25 views

How to calculate half, third, fourth?

I'm trying to calculate some image sizes for Imager. This works: {% set imageSizes = [{ height: imageHeight * 4}, { height: imageHeight * 3}, { height: imageHeight * 2}, { height: imageHeight}] %} ...
1
vote
1answer
20 views

Craft 3 CMS How to get all Channel Names/Titles

I am trying to retrieve all Channel sections' names/titles. This is snippet contains the troublesome part. {% set allSections = craft.entries.all() %} {% for section in allSections %} {% ...
2
votes
2answers
51 views

“Template not found” in live-preview

I am using docker for my local webdev and am new to Craft CMS. Currently I have a simple setup running, however, my Live-Preview does not seem to work and throws the "Template not found" error. Yet, ...
1
vote
2answers
37 views

Which twig file is being used and how?

I have a page in Craft (2.x) that displays several links and I was able to find which twig file had those links by searching the code base of twigs. Those links point to some Angular code with links ...
1
vote
1answer
29 views

How to insert widgets in Rich Text field

I want to insert widgets in arbitrary positions in one of my rich text fields. A good example would be a contact form inserted in the middle of the content. These widgets would be ad units, forms and ...
1
vote
1answer
20 views

User profile page

I'm looking to setup a profile page, displaying a users details (address etc) and they're current membership status (which will be down the Stripe Payments plugin.) I'm having some trouble getting ...
1
vote
1answer
52 views

My month/year archive template code no longer works in 3.2 [closed]

My blog has a date archive page that uses a variation of this code. Here's the code that I've been using: {% set allEntries = craft.entries.section('entries').type(['posts','reviews']).limit(null)....
3
votes
2answers
113 views

How to access HTML input values from Twig and vice versa

I am new to Craft and Twig in general. I have encountered the following problems and struggling to find a solution for hours. I want to access the value of "foo" input field inside the twig ...
0
votes
0answers
25 views

Checking if entry field exists - dot vs bracket notation

Let's say I want to check if the field exists in entry. When I try to check for some no-nexisting field using dot notation it incorrectly returns true - entry.somefield is defined If I use bracket ...
1
vote
1answer
34 views

Get an Asset's Filename Without the Extension

How do I get an asset's filename without the extension? So if my filename is my_cool_photo.jpg I want to return my_cool_photo. Using {{ entry.assetsField.one.filename }} returns the name of the file ...
0
votes
0answers
24 views

Customizing display order of category entries to match admin (order as Structure)

I'm working on a Craft-based site that has a category defined for "Members". I can see in the admin panel one has the ability to drag the entries for this category in any arbitrary order (when ...
1
vote
1answer
27 views

Category query returning one fewer items than requested

I'm building a knowledgebase for a client. The client has asked for content to be restricted by category and then by user. This part is easy enough - the users now use the same category field as ...
1
vote
1answer
39 views

Navigation is throwing Twig error when trying to 'preview' a disabled entry

I have an entry that needs to be disabled until the content is finalized. I am not able to 'preview' the entry unless I enable it. If I remove the navigation code, 'preview' will work on the disabled ...
1
vote
1answer
40 views

Explanation of Deprecation Warnings

Why is this depreciated? Is there an example of the preferred method? Looping through element queries directly has been deprecated. Use the all() function to fetch the query results before looping ...
0
votes
0answers
21 views

Double encoded querystring parameters in pagination urls

Since upgrading to Craft 3.2 I've noticed that my querystring parameters are double encoded in my pagination urls? Example below: /search/p2?s=cancer&t%255B%255D=blog Edited: After a bit of ...
1
vote
1answer
60 views

Render template from Module in twig template

I have been searching around SE and the web in general for an answer to this. There seems to be plenty of solutions but none appear to be working for me. I have a simple module that has a variable ...
0
votes
0answers
18 views

Twig Include is displaying empty modules on page

I have a twig file called "Abilities.twig" inside abilities I have the below code: <p>{{ module.Ability }}</p> In the CMS I have a field set named "modals" with the field block "...
0
votes
0answers
8 views

Feed Me Plugin - can't authenticate when using inside templates

This is in reference to Feed Me's ability to call a feed directly from within a template. My issue that the feed I am hitting requires an authentication header to be sent at the same time in order to ...
1
vote
1answer
40 views

Undefined index error in trying to duplicate file

I've inherited a Craft-based website, and I'm much more familiar with WordPress, so please pardon the extremely basic question: the homepage for this site uses {% extends "_layout" %} and then ...
0
votes
0answers
24 views

Implementing Mollie Payment Gateway

I'm having a bit of trouble with the Mollie Payment Gateway and how it works, the docs are a bit...short. I know that Mollie is an off-site payment gateway, with that I have a few questions: I've ...
1
vote
1answer
49 views

{{siteUrl}} not working on load

I am using {{ siteUrl }} for absolute links. It works 95% of the time. But if I press the reload button multiple times in a few seconds (overloading or something) my links look like this: href="$...
1
vote
1answer
20 views

Merge a structure and a single section

That is written so inefficently: {% set indexNavi = craft.entries.section('pageContent').level(1).all() %} {% set bookingLink = craft.entries.section('booking').all() %} <ul class="navList"> ...
0
votes
0answers
15 views

How would override a single CP template?

I would like to override the "_special/image_editor.html" template, to allow more constraint possibilities. How would override this template ? Nicolas
2
votes
1answer
34 views

Check for number less than x in array

I want to check if there is a number less than 10 in an array. {% if 10 in [0, 30, 50, 10, 9, 200] %} {# checks only if there is a 10 in it. not if there is anything below 10. #} yep. there is ...
1
vote
1answer
13 views

Sort Categories by Entry Updated

I have the following Category loop code which I'm trying to sort by the date the entries within have been updated. e.g if an entry was just updated within a category, this category would be at ...
1
vote
1answer
26 views

Use function provided by plugin only if plugin is installed and enabled

I want to use asset rev in my template, but only if plugin is installed and enabled: {% if craft.app.plugins.getPlugin('assetrev') is not null and craft.app.plugins.getPlugin('assetrev')....
0
votes
0answers
33 views

Removing Plugin from Project.yaml

I'm trying to remove a rogue plugin from my Project.yaml - it's refusing to go! It's not in composer.json It's not in composer.lock It's not in my plugins DB table. It's not in my plugins CP list. ...
1
vote
1answer
31 views

Restricting access to user groups with Control Panel access only

I know I can restrict template output to Admins only with : {% if currentUser.admin ?? false %} …and to any logged in user with: {% if currentUser ?? false %} And I’m aware of accessCp as a ...
1
vote
2answers
75 views

Filter entries with AJAX

How would I sort blog entries displayed using AJAX? What I want to achieve is initially show all posts from a channel (All) but then let my users sort through these posts with a sub navigation using ...
1
vote
1answer
230 views

How to do CSS/JS bundles/minifying in Craft 3

I would like to combine all of my sites JS-files into one bundle - and perhaps also obfuscate it. Same goes for CSS-files. How would I do that in Craft CMS 3?
1
vote
1answer
33 views

Neater way to merge this conditional entry query?

I know there's a better way to do this - eg by merging in the relatedTo parameter if categorySlug is defined rather than defining 2 different queries, but I can't for the life of me figure it out... ...
0
votes
0answers
13 views

Tag list not displaying All Tags

I have this loop, but it's not actually displaying all tags? Is there a reason for this? {% set relatedTags = user.userInterests.all() %} {% if relatedTags|length %} {% for rel in ...
1
vote
3answers
76 views

Paginate Tag Page

I'm looking to paginate my tag page, but unfortuntately it throws a fairly strange error. Remove the pagination -> the page works perfectly? Bit confused, the only thing I think it may be is that it's ...
1
vote
2answers
31 views

Access entry content in _layout.html

I have some content I wish to output in the main parent _layout.html template. Seems like something simple to achieve but can't seem to figure it out. If I call {{ entry.bannerLabel }} etc it throws ...
2
votes
1answer
46 views

How to re-populate form with old values when submitted from a controller?

I have a form in a template which makes a request to the specified action (a controller). The controller decides that there is an issue with the inputs and needs to provide error output for the user. ...
1
vote
1answer
25 views

Craft 2: get default user group from user settings

In Craft 2, I know I can get general config settings. How can I get the current Default User Group (set in Settings > User Settings) for use in my templates?
2
votes
1answer
55 views

Order by Numeric Custom Field Value

I'm trying to order my entries by a numeric custom field named score, some of these values can be 0 but unfortunately, it's not getting ordered at all? {% set users = craft.users.group('influencer')....