Questions tagged [templating]

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

78 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3 votes
0 answers
345 views

JsonLD & Schema

What is the best way to use Json-LD schema in the templates for Craft 3? I would like to dynamically load parts of the info. I know about the SEOmatic plugin but looking for a way to do it on my own.
user avatar
3 votes
1 answer
196 views

Using setTemplateMode on the frontend

I'm trying to access a CP template from the frontend, and i'm doing something like this in my plugin: <?php ... $oldMode = craft()->templates->getTemplateMode(); craft()->templates->...
user avatar
  • 2,957
2 votes
0 answers
741 views

PHP types for Twig in PHPStorm

As this tip (Twitter) suggested we can use type hints for Twig in PHPStorm after installing Symfony Support plugin by utilizing its PHPTypes feature, for example putting: {# @var craft \craft\web\...
user avatar
  • 728
2 votes
0 answers
42 views

Asset Upload Form Field Error States

I currently have an asset upload field, but I'm trying to make it call errors back if the image isn't an extension that's set within the field, allowing users to understand why the form didn't save. ...
user avatar
  • 1,230
2 votes
0 answers
165 views

Add CP Tab content into include file

I am making a plugin where I have about 10 tabs at the top. Depending on the admin users privileges they may see a subset of 1-5 or 6-10 and super admins can see all 10. The issue I am running into ...
user avatar
  • 33
2 votes
0 answers
425 views

Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme"

I'm trying to render a template from a console command, but i'm getting the following error: Craft\ConsoleApp and its behaviors do not have a method or closure named "getTheme" The code looks like ...
user avatar
  • 2,957
2 votes
0 answers
224 views

Setting template mode to CP doesn't let me load plugin templates

Setting template mode to CP with craft()->templates->setTemplateMode(TemplateMode::CP) only lets me load templates from app/templates. If i load app/templates/entries/_fields.html and I use ...
user avatar
  • 268
2 votes
0 answers
500 views

asset.getUrl() outputs double slashes

Craft hasn't done this prior (or maybe I just noticed), but I'm currently battling double slashes in URLs returned from {{ asset.getUrl() }}. The issue appears when I create an Assets field and set ...
user avatar
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
1 vote
1 answer
116 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
0 answers
46 views

Craft 3 entry.author.getPhoto() is coming up null on template, but the author has a photo uploaded in the user > details section, any ideas why?

The site is utilizing a Servd bucket to store all assets. The backend shows a photo successfully uploaded to the user > details section, but does not provide a url in the entry.author.getPhoto(), ...
user avatar
1 vote
0 answers
183 views

Creating a modal popup using CraftCMS and Twig

I've been looking everywhere, I'm trying to create a modal using a global but I can't seem to figure out where to start. JavaScript: $popUp = new Garnish.Modal($('#popUpModal('), $popUp.show(), $popUp....
user avatar
1 vote
0 answers
24 views

Freeform output styling

When rendering the output of a single Star Rating field using the default Flexbox form, the output creates its own styling, overriding what I put in the element it's in... and adds a "float: left&...
user avatar
  • 138
1 vote
0 answers
228 views

Is there a way to include partials in Craft without setting a path?

To separate code and avoid duplication I am trying to split up recurring pieces of twig code into partials (think of a nav or a block of services for example). I tried using include but Craft ...
user avatar
  • 11
1 vote
0 answers
27 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', '...
user avatar
  • 1,834
1 vote
0 answers
27 views

A user cannot change the password without completing the profile

I have an issue. I have custom fields in the user profile, some of them are required. I also have a change your password page and a change your email password. A user can create an account (Without ...
user avatar
1 vote
0 answers
53 views

How can I find out what type of entry is getting used?

I have an include that is being used for plain entries, and is also being used for categories. (Categories have their own urls) {% if entry is defined %} {% set entry = entry %} {% elseif ...
user avatar
  • 4,696
1 vote
0 answers
278 views

Escaping rich text fields to json but keep html markup

I am trying to create an export from an old Craft2 site over to a new Craft3 site. The structure and fields are all different, so I figured the easiest way was to create a json file from my entries ...
user avatar
  • 440
1 vote
0 answers
108 views

What the best strategy to test Craft template?

I would like to know if there is a way unit test templates using Craft 2.5? For example trying to prevent null pointers happening in production when an image is remove from the entry
user avatar
  • 231
1 vote
0 answers
2k views

Calling unknown method: craft\web\twig\variables\CraftVariable::embeddedAssets()

I get this message while trying to access embedded Asset with the plugin Embedded Assets 1.0.2: Calling unknown method: craft\web\twig\variables\CraftVariable::embeddedAssets() I was fiddling around ...
user avatar
  • 11
1 vote
0 answers
34 views

How to handle URLs of entries with no category?

I have a section where most entries have a category assigned to them, but a few ones have no category at all. I need help how to connect these entries' URLs to my entry template. So far I used a ...
user avatar
1 vote
0 answers
29 views

Entries sorted by title have some entries not alphabetical

I have the following code to return some grants, but whilst most of the entries are coming back alphabetically ordered, after the last "Z" entry, there are a few more entries also alphabetically ...
user avatar
  • 912
1 vote
0 answers
27 views

Recursive relations – how to build list properly?

I started building a list of recursive relations: We're in a project, we want to check interviews related to that project, see which persons participated in those related interviews, and then build ...
user avatar
  • 589
1 vote
0 answers
273 views

Craft CMS 3 create custom field in plugin with two fields returning two values

I need to get two text fields under the same custom form and have it return two different values to be stored in the database. Right now with what I have, it's storing the same variable for both, ...
user avatar
  • 11
1 vote
0 answers
258 views

Categories and Sub Categories

Good morning and thank you in advance. Very to new Craft and Twig so I am not sure if I am coding this correctly but need some help. I have a forms center that has 5 main categories (Members, ...
user avatar
  • 107
1 vote
0 answers
57 views

Commerce: reading Stripe object in Craft Transaction model

I'm looking to add the credit card last four digits to my customer's frontend order history. Stripe is the gateway. The Stripe transaction object doesn't seem to be available in the Craft ...
user avatar
  • 631
1 vote
0 answers
159 views

Access array from the static translation file

This is the scenario: I need the translations strings in both Twig and JS (For React). Of course I'm covered in the Twig part., and I don't want to maintain two different files (php and json). So I've ...
user avatar
1 vote
0 answers
43 views

How to test if a address is on a list before it gets added? (MailChimp Subscribe Plugin)

I’m working on implementing this plugin: https://github.com/aelvan/mailchimp-subscribe-craft I’m wondering: How can I accomplish to test if an address is on the list before it gets added? And on top ...
user avatar
  • 215
1 vote
0 answers
56 views

Is this an ok approach to building a secondary navigation?

I have a site which has multiple menus e.g. primary and utility. I've built the menus via sections and the entry type for those sections has a title and a entry field. This site requires me to show a ...
user avatar
1 vote
0 answers
178 views

Refresh "hidden" template after login with ajax

I am trying to create a seamless user login interaction with a modal form using ajax. Let's say I have a navigation template _navigation.html <div> {% if currentUser %} {{ currentUser }}...
user avatar
  • 195
1 vote
0 answers
42 views

chain of random entries based on relations

I'm developing a bio section for a client. Every bio is linked to another bio creating a chain of bios. The order of this chain should be random. The schema would be as following: Bios: Bio a, Bio b, ...
user avatar
1 vote
0 answers
234 views

making a dynamic menu in a template

Sometimes the links are in-page, sometimes they point outside. I want to be able to create an array menuitems that is passed to an include and which then generates a per-section index menu on the page....
user avatar
  • 111
1 vote
0 answers
100 views

AMForms - How to use dynamic formHandle

I have a basic contact form set up and working but I've now got to change it to make it support locales. So depending on what language version of the website you are looking at, the form submits to a ...
user avatar
1 vote
0 answers
58 views

When constructing an ECM, is it possible to compare two values?

My section has two numeric fields, lorem and ipsum. It's possible for users to enter any integer they want into these two fields. I want to grab all results where lorem is greater than ipsum. Here's ...
user avatar
  • 23.6k
1 vote
0 answers
135 views

How to create an archive dropdown menu

How do I create a dropdown menu that filters all the posts into month and year, and then link to a template that has the entries of that month and year displayed? This is as far as I've gotten: <...
user avatar
  • 11
1 vote
0 answers
27 views

Add jplist script to Craft CMS

I found this useful search, sort and filter script http://jplist.com, which I have added to my website. It works perfectly until I realize that when my database grow to the point it slow the page down....
user avatar
1 vote
0 answers
95 views

Simpler way to code up a category conditional?

I've coded up conditional for categories. I'm still new to Twig and curious if there is a simpler way of coding the following. {% for feedItems in craft.entries.section('news').limit(null).offset(1)....
user avatar
  • 317
1 vote
0 answers
184 views

Smart Map search not working with Province

I'm building out a store locator map and everything is going well. All store locations get output on the map and when I search with either a city or a postal code the map filters the results correctly....
user avatar
  • 1,907
1 vote
0 answers
117 views

I'm repeatedly setting the same variables. How to reuse code block to make this DRY?

I have a very complex layout which is requiring me to have quite a few {% for %} loops on the page and in each loop I need to set a bunch of variables. In order to make my template more DRY I was ...
user avatar
1 vote
0 answers
141 views

How to get the order index of a structure entry?

I have a structure with 3 levels. The first 2 levels are for structuring the content and most of the content comes from the 3.rd level. This 3.rd level are the entries which are written by different ...
user avatar
  • 11
1 vote
0 answers
122 views

How do I get an input value to dynamically update a Craft query on each keypress?

I want to set a Javascript variable using a Craft variable. Is this possible? {% set searchJs %} $( "#search" ).keydown(function() { var query = document.getElementById('search').value; {% set ...
user avatar
1 vote
0 answers
99 views

Where to find info on Entry URL Formats and routing syntax/options?

Is there any documentation other than on the CraftCMS web site with details and examples of Entry URL Format options/syntax? I came across an example from Brandon Kelly in this thread yesterday which ...
user avatar
  • 215
1 vote
0 answers
55 views

Return Category from Inside Matrix

I'm having difficulty returning a category from inside a matrix block. So I'm returning a student based on a studentNumber variable {% set studentParams = { section : 'students', '...
user avatar
1 vote
0 answers
3k views

How to get a param from an ajax request in twig?

Ok this has been puzzling me for too long now! I have some code that makes an ajax request: reqAjax: { type: 'get', url: '/mytemplatefolder/myfile.html', data: {town: 'bournemouth'} } ...
user avatar
  • 2,023
1 vote
0 answers
520 views

Error with compiled Twig templates

Occasionally, after deploying Craft, without warning I am unable to access the admin dashboard and get the following PHP error: PHP Parse error: syntax error, unexpected '.', expecting '&' or ...
user avatar
1 vote
0 answers
145 views

Implement a compare products funcionality

I´m working in a buggy´s website, and i want to implement a "compare" functionality, where the clients can check some products from the list ( a checkbox in each product ) and be able to compare the ...
user avatar
0 votes
0 answers
14 views

How to add Field to Template hook cp.entries.edit.settings and save value to entry?

I'm trying to show a custom lightswitch field inside the right panel on the edit page of an entry and saving its state to the entry when the user clicks on save. My form template looks like this: <...
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
36 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
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