Multiple template events to choose.

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
hexplor
Registered User
Posts: 31
Joined: Sat Feb 16, 2008 3:34 pm
Name: Karol

Multiple template events to choose.

Post by hexplor »

Hello Again,
I'm getting deeper and deeper into whole extensions system and I'm loving it. I have a question though.

Basically when I want to create an extension and I want to inject code into template event I simply create file with corresponding template event name: acp_overall_footer_after.html inside extension root styles/adm/template/event. That's clear for me.

Another scenario:
I want user to pick template event in my extension. Let him choose where he wants to inject the code: (header template event,footer template event, etc..) Is that possible ?
Normally i would just create different .html files with triggers for different template events. But that would result in dozen of the same files with different event names. So another possibility: I can use php to rename file into event user selected. But that's a workaround..

So my question is. Is there a possibility to inject code into TEMPLATE events using php for example ?
nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: Multiple template events to choose.

Post by nicofuma »

If you define all of these events like that:
(in header)

Code: Select all

	<!-- IF S_INCLUDE_MY_EVENT_IN_HEADER -->
		<!-- INCLUDE my_event_core.html -->
	<!-- ENDIF -->
(in footer)

Code: Select all

	<!-- IF S_INCLUDE_MY_EVENT_IN_FOOTER -->
		<!-- INCLUDE my_event_core.html -->
	<!-- ENDIF -->
and you use a php event to define the two template vars.

does it solves your problem?
Member of phpBB Development-Team
No Support via PM
User avatar
hexplor
Registered User
Posts: 31
Joined: Sat Feb 16, 2008 3:34 pm
Name: Karol

Re: Multiple template events to choose.

Post by hexplor »

Hmm.. not sure if i get it..
I was talking about template events. They are being declared inside html files by using:

Code: Select all

<!-- EVENT identifier -->
So basically I was asking if you can target/reach this event using PHP or at least somehow with Twig...
nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: Multiple template events to choose.

Post by nicofuma »

but what do you want to do with that?
if you want to condition the execution of an event, I don't see another solution:
1) You use a php event (basically related to the header) to set a variable saying if the event should be used
2) In the event's html file, you surround your code with a IF dependent on the variable you added before
Member of phpBB Development-Team
No Support via PM
User avatar
hexplor
Registered User
Posts: 31
Joined: Sat Feb 16, 2008 3:34 pm
Name: Karol

Re: Multiple template events to choose.

Post by hexplor »

let's say i created an extension, simple information slider or weather mod.. whatever... And i want give user ability to choose where he wants the module to be displayed. By using php core events this is somehow limited to header,footer and few other places.. By using template events it's way more robust and kinda made for that purpose because you can create events yourself and use lots of ones created already..
Sorry if that sounds a little bit enigmatic.. I was just wondering how <!-- EVENT identifier --> is made..
nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: Multiple template events to choose.

Post by nicofuma »

well,
<!-- EVENT identifier --> is very simple:
all the template's files contained in ext\<vendor>\<ext>\styles\<style>\templates\event\<event_name>.html are included

So if you add an event template file for each of the possible locations you will see your module (weather, information...) on each places. To avoid this you have to surround your code in the events with an IF. And to avoid the repetition of the template code (the code which really display the event) you can INCLUDE another template file which will contain the real code
Member of phpBB Development-Team
No Support via PM
Post Reply

Return to “Extension Writers Discussion”