Hot answers tagged

14 votes
Accepted

Is there a way to define a global var within a twig block?

Twig variables are only accessible inside their own scope. . What is a scope: Tags like {% block %}, {% for %}, {% nav %} create a 'scope', which means that variables defined inside them, can't be ...
user avatar
  • 8,316
11 votes
Accepted

The safest way to edit core Craft files?

You should never edit the core files (i.e. anything below /app), because whatever changes you add might be overwritten any time Craft is updated – or even worse, your amendments might conflict with ...
user avatar
6 votes
Accepted

How do I extend another plugin?

I believe what you asking about are Hooks and Events. Craft has several of them listed in the Hooks Reference and Events Reference. And Craft also allows us to add Hooks and Events in our plugins, ...
user avatar
  • 13.2k
4 votes

Send a block... into a block?

It seems to be what you need is Twigs extend functionality. What you have here is a very common template structure so there is nothing out of the ordinary! Firstly, going from your code I'd recommend ...
user avatar
  • 3,594
3 votes
Accepted

Send a block... into a block?

Unfortunately, there's no way around having the {% block %} tag somewhere in the template that's being extended. In other words, your main layout template it's going to have {% block %} tags. However,...
user avatar
3 votes
Accepted

Override a portion of an extends template

You could define a variable in you child template: {% set bodyAttributes = 'onload="load()" onunload="GUnload()"' %} And then output the value in your parent _layout.html template. Use the is ...
user avatar
  • 35.8k
3 votes
Accepted

What happens when extending an extended template?

So I tried it, made three files, one extending the first, and another extending the second, and it all worked more or less as one would expect. bozo.html <!DOCTYPE HTML> <html> <...
user avatar
  • 1,263
3 votes
Accepted

Change title url of elementtype in the list

I found the solution of this was under my nose, I added this public function populateElementModel($row){ $model = Plugin_ClientModel::populateModel($row); return $model; } In ...
user avatar
  • 427
3 votes

How do I extend another plugin?

There are two ways you could get something like this to work: If the other plugin fires an event when at a point in the code where your plugin wants to do something, you can just listen for that. (...
user avatar
3 votes

Is there a way to define a global var within a twig block?

This article may help as well: Twig Processing Order & Scope
user avatar
  • 10.9k
3 votes

Templating basics: extend, include or use?

My setup regarding includes for templates is as follows: I'll have a 'site' structure that looks at /pages/_entry.twig for it's template. But I'd have a range of entry types within this structure, ...
user avatar
  • 1,032
2 votes

Plugin Development: extending a vendor plugin

In your example, if you do this: $var = new \XXX(); $var->doThis = 'CONTENT HERE'; Then doThis will never exist for class \XXX because \XXX isn't where the method was defined. It would work from ...
user avatar
  • 66.4k
2 votes

Templating basics: extend, include or use?

I use extend for different entry types. So i have a master.html with the main html construct and includes page parts like header.html and footer.html Then i have a standard.html that extends master....
user avatar
  • 685
2 votes
Accepted

Templating basics: extend, include or use?

Hmmm I think I've got it already: _layout.html <!DOCTYPE html> <html lang="de"> {% include "pages/partials/_head.html" %} <body class="body"> {% include "pages/partials/_header....
user avatar
  • 589
2 votes
Accepted

Not triggering SEOMatic on save element

By setting the regenerateSitemapsAutomatically to false, SEOMatic won't regenerate a sitemap for every entry saved. At the end of the job, I set it back to true and save the first element inside of ...
user avatar
  • 195
1 vote
Accepted

How to Extend Craft CMS frontend controller?

Experimented a short while ago on how to do it via a custom module, which I think is cleaner than messing around with craft's own stuff. (Spoiler: It's faster than twig, but not that much) You have to ...
user avatar
1 vote
Accepted

Can a plugin manually raise another plugin's Event?

I've built a plugin which uses it's own events before, I guess the way to do it would be the same for separate plugins, however this is untested for your use case. This should go in your plugin ...
user avatar
  • 4,519
1 vote

Set Parent Template Defined Content to Output in Child Template

You could use include...with, as specified in the Twig Docs here Example for your case: {# in Template C #} {% include 'template-d.twig' with {'foo':'Hello World'} %} This should give Template D ...
user avatar
1 vote

Custom Asset Source Types - not possible

Custom Asset sources are not possible in Craft 2 without some core hacking. However totally doable in Craft 3 (even in the dev preview). There is an example of how to pull it off here.
user avatar
  • 66.4k
1 vote
Accepted

How to extend UserRecord?

When extending Craft's active record classes (like UserRecord), you'll only be able to setup the AR relationships one way (from your class to Craft's i.e. MyPortal_ProxyUserRecord => UserRecord) as ...
user avatar
  • 66.4k

Only top scored, non community-wiki answers of a minimum length are eligible