Questions tagged [templating]

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

79 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
0answers
244 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
152 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
119 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\...
2
votes
0answers
25 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
184 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
106 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
368 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
187 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
416 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
1answer
21 views

Formatting Issues

I need help formatting my pages. Right now the way my CMS is formatted, All the paragraphs of copy I put onto any given page get broken up into columns and it is very frustrating and I haven't a clue ...
1
vote
0answers
56 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 ...
1
vote
0answers
21 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
139 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
24 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
38 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
147 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
66 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
783 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
25 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
24 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
17 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
164 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
182 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
42 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
98 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
42 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
53 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
135 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
39 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
167 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
97 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
1answer
666 views

Create custom field to input canonical url in a page

What is the best way of creating a custom field for each page whereby the user can input a URL into a field, which then gets input into a rel=canonical element like the example below. <link rel="...
1
vote
0answers
51 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
115 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
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....
1
vote
0answers
93 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
145 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
96 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
110 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
100 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
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 ...
1
vote
0answers
51 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
499 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
119 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
11 views

Get entries from a specific level (4) of categories, but go back up the levels if there is not enough content

What would be the best way to achieve this in twig logic? All entries are related to categories. These categories could be between 1 -> 4 levels deep. I would like to start at the deepest level and ...
0
votes
0answers
13 views

Building a tab component in a matrix content builder - child matrixes with SuperTable plugin

There are similar questions and answers, but I'm not finding any that are answering my specific questions. I've built a content builder with a matrix in Craftcms like these tutorials have gone over. ...
0
votes
0answers
56 views

Overwrite template-files

I want to use one template on several Craft websites (different installations, not multi-sites). Is there a way in Craft I can do something like this? I want to update/overwrite the /templates/core/ ...
0
votes
0answers
10 views

Cached Images falling back to IP

I'm having a strange problem which I'm unsure if it's my hosting or my Craft's config. My images which I have within a Cached template, once the cache expires or sometimes before they go back to the ...
0
votes
0answers
15 views

Craft CMS 2.9.2 template issue

My script looks like <div class="xl-left"> <h5>Rock</h5> <ul class="list-reset filters__list" data-filter-group="type"> {% for category in craft.categories....