-
Notifications
You must be signed in to change notification settings - Fork 0
2: Naming conventions & component variants
As you saw in my HelloWorld
-example above, Twack requires class and file names to be in a fixed format. (Controller-) classnames need to be written in Upper-CamelCase. Every filename and directory is, contrary to classnames, required to be specified in underscore_notation.
Please make sure that your class names do not match the names of ProcessWire core or module classes. That's how you avoid name collisions in the ProcessWire namespace with already existing classes.
If you need your component be available under another component name it can be useful to add an alias:
wire('twack')->addComponentAlias('HalloWelt', 'HelloWorld');
// Call for "HalloWelt", but get the "HelloWorld"-component:
$myComponent = wire('twack')->getNewComponent('HalloWelt');
This makes our HelloWorld
-component also available under the component name HalloWelt
. As an additional third parameter you can pass custom arguments to only the alias component.
wire('twack')->addComponentAlias('HalloWelt', 'HelloWorld', ['title' => 'Hallo Welt!']);
// Call for "HalloWelt", but get the "HelloWorld"-component:
$myComponent = wire('twack')->getNewComponent('HalloWelt');
Every HalloWelt
component will now have the title "Hallo Welt!" for default, while the HelloWorld
components still have "Hello World!" as default. I recommend to not overstrain the alias functionality - finding the original component for an alias can take a while and make your code less readable.
Twack
Reusable components for your ProcessWire-templates!
ProcessWire-Module: | https://modules.processwire.com/modules/twack/ |
Support-Forum: | https://processwire.com/talk/topic/23549-twack/ |
Repository: | https://github.com/Sebiworld/Twack |
Wiki: | https://github.com/Sebiworld/Twack/wiki/ |