We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [templating]

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

73 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
230 views

Using plugin template on front end

I'm working on a plugin called modelselector and I want to use a template stored in the plugin templates folder but it should be shown on the front-end of the website. Currently the following direct ...
3
votes
1answer
137 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->...
2
votes
0answers
20 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. ...
2
votes
0answers
163 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.
2
votes
0answers
87 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 ...
2
votes
0answers
339 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 ...
2
votes
0answers
173 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 ...
2
votes
0answers
376 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 ...
1
vote
0answers
17 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
50 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 ...
1
vote
0answers
19 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 ...
1
vote
0answers
33 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 ...
1
vote
0answers
104 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 ...
1
vote
0answers
53 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
1
vote
0answers
525 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 ...
1
vote
0answers
23 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 ...
1
vote
0answers
23 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 ...
1
vote
0answers
14 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 ...
1
vote
0answers
102 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, ...
1
vote
0answers
150 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, ...
1
vote
0answers
34 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 ...
1
vote
0answers
65 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 ...
1
vote
0answers
41 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 ...
1
vote
0answers
45 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 ...
1
vote
0answers
126 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 }}...
1
vote
0answers
37 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, ...
1
vote
0answers
139 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....
1
vote
0answers
92 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 ...
1
vote
0answers
49 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 ...
1
vote
0answers
98 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: <...
1
vote
0answers
25 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....
1
vote
0answers
92 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)....
1
vote
0answers
123 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....
1
vote
0answers
90 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 ...
1
vote
0answers
102 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 ...
1
vote
0answers
96 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 ...
1
vote
0answers
97 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 ...
1
vote
0answers
45 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', '...
1
vote
0answers
2k 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'} } ...
1
vote
0answers
483 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 ...
1
vote
0answers
108 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 ...
0
votes
0answers
12 views

Set Up Route to Template - then variable Entry is undefined

I've got a blog listing channel set up where I'm trying to filter entries listed by the entries field blogAuthors based on url segment. /articles-and-excerpts/ loads the blog fine added a route but ...
0
votes
0answers
9 views

Flexible List Template for Entry Types

Not sure what I'm missing here or maybe it's not as simple as I think it is, but I'm trying to create a listing template for entry types and I don't want to create a template folder or file for each ...
0
votes
0answers
18 views

Ordering merged entries

I have a requirement where I need to display entries from one channel, but entries get might show up 5 days after post date, show up if externalListingOnly or show up immediately if ...
0
votes
0answers
10 views

Craft 2: when searching for an entry can you select an entry by a fields value?

I have an entry in the section microsites these entries all have a required field called accessCode. I have the access code in a variable. I want to load in only that entry. Is this possible without a ...
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 ...
0
votes
0answers
26 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 ...
0
votes
0answers
26 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 ...
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 ...
0
votes
0answers
19 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 "...