News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Mod developer question: How do I replicate theme edits inside my Mod.php file?

Started by Wellwisher, March 30, 2016, 01:34:39 PM

Previous topic - Next topic

Wellwisher

I have "hooked" in all my functions (thanks to @Margarett's hooks tutorial & advise from @Jblaze, @Nend & @Shambles - yay!).
Feels AWESOME8) I am now left with *one* line of code which requires a theme edit, and I am lost - because it involves php.

This following example snippet is from "Install.XML" of a mod which packman uses to execute add/ replace operations in theme files.

My question is: How do I make this type of edit to a theme file from my Mod.php (is it possible?) without resorting to editing them:

<file name="$themedir/Display.template.php">
<operation>
<search position="before"><![CDATA[// Show the post itself, finally!]]></search>
<add><![CDATA[
// Enter my code
                           ]]>
</add>
</operation>
</file>

JBlaze

I'm not sure I understand what you're asking entirely. You want to make a template edit after the mod has been installed? If so, why? It's much, much easier to make the edit when installing the mod itself.
Jason Clemons
Former Team Member 2009 - 2012

Wellwisher

I am failing to add code to display.template.php during the mod installation from inside my mod file.

Basically this hooking business is rather addictive and thus, I want this to happen from inside my mod file. Doesn't look like there is a hook to add code inside display.template.php?

JBlaze

What exactly is failing? Is it giving an error on install, or is it not adding the actual code to the template?
Jason Clemons
Former Team Member 2009 - 2012


Illori

without the actual code you are trying to add and what is in your mod file, we can guess all day as to why it is failing and never have the exact right answer.

Wellwisher

Quote from: Illori on March 30, 2016, 02:40:22 PM
without the actual code you are trying to add and what is in your mod file, we can guess all day as to why it is failing and never have the exact right answer.

Hello Illori,

I am asking in general in SMF. Say if I wanted to add a line of code to a $theme directory file. How can this be achieve from my mod file? Is this possible/ allowed?

Resorting to install.xml to make these edits happen, makes me feel like a dirty hobo. :-\

Illori

many mods do this. check the mods on the mod site otherwise we cant tell you what may be going wrong.

Wellwisher

Quote from: Illori on March 30, 2016, 03:16:31 PM
many mods do this. check the mods on the mod site otherwise we cant tell you what may be going wrong.

If it's not too much trouble can you refer me to a mod that does this (maybe your own)?

JBlaze

Quote from: Wellwisher on March 30, 2016, 03:10:10 PM
Resorting to install.xml to make these edits happen, makes me feel like a dirty hobo. :-\
That's how SMF modifications work... So unless you want to rewrite the package manager, use install.xml for your file edits.
Jason Clemons
Former Team Member 2009 - 2012

Wellwisher

Quote from: JBlaze on March 30, 2016, 03:33:13 PM
Quote from: Wellwisher on March 30, 2016, 03:10:10 PM
Resorting to install.xml to make these edits happen, makes me feel like a dirty hobo. :-\
That's how SMF modifications work... So unless you want to rewrite the package manager, use install.xml for your file edits.

My d00d, Illori said it's possible but he's hogging the trade secert or making me look for it like a needle in a hay-stack.  :P

Quote from: Illori on March 30, 2016, 03:16:31 PM
many mods do this. check the mods on the mod site otherwise we cant tell you what may be going wrong.

Illori

yes many mods add edits to the install.xml file for theme edits... that is what you asked about.

Wellwisher

Quote from: Illori on March 30, 2016, 03:55:27 PM
yes many mods add edits to the install.xml file for theme edits... that is what you asked about.

So this is not possible to do via my Mod.php file? That's my original question, be it a little confusing to understand.  ::)

JBlaze

Jason Clemons
Former Team Member 2009 - 2012




Matthew K.

Quote from: Wellwisher on April 03, 2016, 05:46:52 PM
Quote from: JBlaze on March 30, 2016, 04:17:01 PM
Quote from: Wellwisher on March 30, 2016, 04:01:52 PM
So this is not possible to do via my Mod.php file?
Nope.

Guys can a work-around be achieved using php namespaces?
Namespaces aren't even related or even close to what you're trying to do unfortunately. While the majority of responders are right, there are some cases that you could use a hook or another clever hack to not modify a theme file - actually, there are very few cases you couldn't, just depends on how much work you want to go through, and or whether it's more of a load to just do an edit (which is no big deal), or hack it in. What code are you trying to add, and where are you wanting it to go?

Wellwisher

Quote from: Matthew K. on April 03, 2016, 06:43:36 PM
Namespaces aren't even related or even close to what you're trying to do unfortunately. While the majority of responders are right, there are some cases that you could use a hook or another clever hack to not modify a theme file - actually, there are very few cases you couldn't, just depends on how much work you want to go through, and or whether it's more of a load to just do an edit (which is no big deal), or hack it in. What code are you trying to add, and where are you wanting it to go?

I need to "Add" one line code specifically to Display.template.php & Recent.template.php. Whilst I know this can easily be done using the traditional "Add/ Replace" method; I rather digg the thought of achieving this from inside MyMod.php file.  ::)

It's not like I am "Replacing" or "Modifying" existing file codes. Wouldn't it be great if  SMF developers could "Add" new codes from their mod file but prevent them from either "Replacing" or "Modifying" exisiting code? Meh, tiss an idea.  :P

Kindred

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Advertisement: