Advertisement:

Author Topic: loadPartialTemplate function Please?  (Read 25297 times)

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #20 on: November 08, 2015, 10:49:57 PM »
1 quick way I see to solve this, is to use php comments within the function template files as insertion points, for either before or after, and tell Theme authors to leave comments intact, or move them to the appropriate place.  Which I don't see why Theme authors would want to remove comments anyhow, since all template files are stuck coming from the Source file anyways.  Than they could even add more comments within the function that could also act like insertion points.  If comment doesn't exist, Mod Template doesn't get inserted.  This gives another option for Mods to have their own templates that can work in all themes.

Ofcourse, this is probably too ugly for SMF to consider using comments within template file functions for insertion points of other templates in Mods, but it's the most logical way to go IMO.  It wouldn't be the first time php comments were used for something useful in a php application, other than being just a php comment.

The benefits of being able to supply your own template file, for any file that gets loaded in SMF (or even another MOD/Theme) via loadTemplate, outway the ugliness of using comments as hooks for this, TBH.  Removing HTML from a template, would be simply removing the file, instead of touching the actual template file instead.  Nothing cleaner than that.  Hell, comments can also have keys associated with them to make it cleaner.

If this is handled in code, instead of writing to the actual template file, I can see less errors with installs, better handling of templates, and Theme Authors not needing to account for Mods when coding their themes as much as they do now, I'm sure.  I'm sure there are even more benefits to hooking into a template file than I have listed.  I would say, it might even be a good idea to provide a priority integer for the function hook that does this, to load the mod template in the priority defined by the hook call.
« Last Edit: November 08, 2015, 11:22:36 PM by SoLoGHoST »

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #21 on: November 09, 2015, 12:15:47 AM »
Nevermind about comments.  Prob not possible using that approach anyways.  Just thinking out loud here...

Just entertaining myself on that thought, kinda flawed and incomplete tho:

Code: [Select]
$tokens = token_get_all(file_get_contents('C:\wamp\www\smf2.1\Themes\default\Display.template.php'));
$comments = array();
foreach($tokens as $token) {
    if($token[0] == T_COMMENT || $token[0] == T_DOC_COMMENT) {
        $comments[] = $token[1];
    }
}

foreach($comments as $comment)
{
    if (strpos($comment, '// Show the message anchor and a "new" anchor if this message is new.') !== FALSE)
template_function($comment);
}

function template_function($comment) {

echo 'Hello World
<p>The comment = ' . $comment . '</p>';

}

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,969
  • Kaizoku Jotei
    • SMF mods
Re: loadPartialTemplate function Please?
« Reply #22 on: November 09, 2015, 09:09:15 AM »
Calling ob_start and ob_end on your function its not a good idea, your function will be executed on each and every message been displayed so calling those ob functions 10, 15 or 20 times per page its going to have some severe server issues.

There is no need to do all the stuff you are doing, on 2.1 the custom profile system has been expended to cover more places and to be usable by mod authors outside merely adding more custom profile fields.

There is a placeholder just below the message, you could use that to inject your html code, it will be totally compatible with whatever theme and you will avoid file edits.

Take a look at the links I previously gave:

https://github.com/MissAllSunday/ActivityBar/blob/master/Sources/ActivityBar.php#L91
https://github.com/MissAllSunday/ActivityBar/blob/master/Themes/default/ActivityBar.template.php#L29

another example of a mod using that system:

https://github.com/MissAllSunday/Breeze/blob/develop/Sources/Breeze/Breeze.php#L740
https://github.com/MissAllSunday/Breeze/blob/develop/Sources/Breeze/BreezeMood.php#L153


Your mod will be much easier to deploy since you don't have to worry about personal messages and the profile page, those pages also shows the custom fields but your mod is solely focused on messages instead of users, thus you only need to use the hook you are already using (integrate_prepare_display_context).

Now, if your mod's html doesn't fit inside the li tag or you don't want to use that approach then you can still made an edit on Display.template.php files.

There is nothing wrong with doing a template edit providing you do it in the correct place and with minimal intermission, if all your logic is properly handle in your source file then you don't need to worry about other mods messing with your code  and by keeping all the style and css to the theme author you don't have to worry about theme compatibility either.

Just because the system lets you replace an entire file with some new code doesn't mean that you will do it, properly placed and minimal presentation-only edits, combined with proper code architecture and a complete separation of logic and presentation really does help keeping the annoying support requests down, just take a look at my mod's support request, I don't get any support request to "make my mod compatible with X theme". All support request I receive are about actual flaws in the mod or custom enhancements. This includes compatibility too.
I'm not a criminal.
I'm not a rapist.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #23 on: November 09, 2015, 12:30:54 PM »
Ok, no problem.  I think I understand what you are saying if I read between the lines.  Seems your responses are in code also.  Basically what you are saying is this is not a request that SMF will do.  Use the template file, and SMF will not add any hooks into templates to help process this better/cleaner.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 54,072
  • Gender: Male
    • Kindred-999 on GitHub
Re: loadPartialTemplate function Please?
« Reply #24 on: November 09, 2015, 12:52:14 PM »
almost.... without your twist on the statement....

there are better ways to do the things that you seem to want to do - which do not involve editing the template or template system. Using hooks and SOURCE files instead of direct editing templates is one of those better ways. Since a better way exists, we have no plans to further complicate things by adding such additional functions into the template system.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,969
  • Kaizoku Jotei
    • SMF mods
Re: loadPartialTemplate function Please?
« Reply #25 on: November 09, 2015, 01:23:27 PM »
Ok, no problem.  I think I understand what you are saying

Huh, no you clearly not. This whole topic fully demonstrates you haven't payed any attention to any of what I said and instead keep on focusing on your "my way or the highway" attitude and pretty much you just read what you want to read. No point in keeping up responding anymore, even if its just to correct some blatantly wrong assumptions about SMF.
I'm not a criminal.
I'm not a rapist.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #26 on: November 10, 2015, 01:37:08 AM »
Ok, thanks for proving me correct.  I think I lied in last statement when I said, "The People are Great".  I think the people is the main reason why I quit customizing for SMF.  It's people like you Suki that adds nothing but ignorance to topics, and pushes people away.  I don't even care what you guys do, I don't want it my way.

I could care less what way it gets done.  Do whatever you want.  I only make suggestion.

Inflammatory comment removed.  There's no need for that - Iris.
« Last Edit: November 10, 2015, 05:14:36 AM by Irisado »

Offline live627

  • Developer
  • SMF Hero
  • *
  • Posts: 5,254
  • Gender: Male
  • Cat: Destroy!
    • live627 on Facebook
    • live627 on GitHub
    • live627 on LinkedIn
    • @live627 on Twitter
    • livemods
Re: loadPartialTemplate function Please?
« Reply #27 on: November 10, 2015, 06:12:42 PM »
Looking at your code, you should

- remove the output buffering
- assign markup to a variable and return it
- edit the display template to inject your line

Quote
Seems your responses are in code
No, her replies are not in binary.

Quote
Basically what you are saying is this is not a request that SMF will do
ignoring the confusion oveer the name (SM vs SMF), this is possible usisng verry hackish code.
Try not to become a man of success, but rather try to become a man of value.
- Albert Einstein

Offline 青山 素子

  • Server Team
  • SMF Super Hero
  • *
  • Posts: 16,975
  • 戦場ヶ原、蕩れ!
    • srvrguy on GitHub
    • @motokochan on Twitter
    • Nekomusume Moe
Re: loadPartialTemplate function Please?
« Reply #28 on: November 10, 2015, 09:50:51 PM »
At the risk of piling on, the issue is that when doing proper coding, you shouldn't stick a lot of logic in the template (view). You should only have the minimal logic needed to display values. This will make your code less intrusive, better contained, and also much easier to update when SMF updates.
Motoko-chan
Director, Simple Machines

Just because it's pouring down doesn't mean we're gonna drown. There's a time when all you can say is let it rain - Mat Kearney (Let It Rain)

Note: Unless otherwise stated, my posts are not representative of any official position or opinion of Simple Machines.


Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #29 on: August 07, 2016, 07:34:24 PM »
Hey, everyone, sorry for my replies.  Have been going through a lot of stuff in my life during all of that and well, just reading over my reactions to comments in here, I see that I was acting very wrong and stubborn.  Just wanted to apologize to everyone, but I also want to say that SMF does need better theme customization for Modifications (Not theme developers).  But I think this is a restriction due to the way the Core of SMF was built, which I believe would make sense to change.

Simply was asking for a way to change the look of SMF completely within a Modification without touching the default template files, which is very possible to do in other systems (e.g. Wordpress).  I have been working in other CMS's and, while SMF is a great forum software, and have had a lot of fun coding for it in the past, it doesn't have the power of flexibility that it should have to make it even greater.  But that is, I guess, what a Forum is, and you've all made a great forum software, but that's all it will ever be.

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 66,703
    • Arantor on GitHub
Re: loadPartialTemplate function Please?
« Reply #30 on: August 08, 2016, 01:54:35 AM »
SMF's interface is massively more complex than WP's because out of the box it does a whole lot more.

Still can't see what you're actually asking for though, beyond breaking templates up a bit.

Then again you are talking to a guy who ports WP themes to SMF...
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #31 on: August 16, 2016, 01:22:39 AM »
So, in Wordpress, you can create a plugin.  The plugin can have it's own templating structure, and the templating structure can call on built-in functions such as add_filter and add_action that can further extend your plugin.  By further extending your plugin, I mean, that someone can create another plugin that relies on your plugin, and extends it for whatever filters you have installed on your plugin.  As a bonus, if your plugin calls upon any of the thousands of wordpress built-in filters/hooks, this can be used by the other plugin to modify it (with priority) and pinpoint the filters and/or actions used by the other plugin.  This creates sort of a cascading affect of PHP, which kinda makes coding a bit more flexible and fun.  Converting a WP Theme, would mean that you would need to open up the functions.php file within a WP Theme and you would run into trouble with filters/actions possibly.  One such action could be the wp_enqueue_script action, admin_enqueue_script or even wp_head, wp_admin_init, wp_init.  Themes for WP can do much more than change the appearance of the front-end, they can also modify the backend.  I know SMF provides a way to add menu's etc., but it's not exactly the same.  There are Widgets also in Wordpress that can be bundled with Themes.  I would think that your conversions of Wordpress Themes are not exactly a 1-to-1 conversion.  More likely an appearance only conversion.  SMF just doesn't provide the means to edit the default templates in SMF (without editing those templates directly, or creating a new theme, which would require creating your own code entirely in the Source to accommodate your theme).  SMF doesn't really provide the flexibility of re-using their built-in functions for other purposes other than what the default theme really provides.  There really isn't a flexibility with SMF built-in functions that Wordpress has available with filters and actions.  Take a look at Woocommerce Plugin for Wordpress, and how many different extensions there are for it.

I haven't used the newest version of SMF yet, so maybe I am not entirely correct in what I'm saying here, but from past experiences...

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 66,703
    • Arantor on GitHub
Re: loadPartialTemplate function Please?
« Reply #32 on: August 16, 2016, 02:58:58 AM »
SimpleDesk was doing the whole plugin of a plugin thing five years ago. With hooks for no file editing, for good measure.

The problem in SMF is that the current templates are too monolithic and can't individually be replaced out. Other than that everything you're talking about has been doable in SMf for years, just no one wanted to do it.

Theming SMF is a larger job than theming WP because you don't have a simple semi generic interface to serve, and plenty of plugins foul up on different themes. I work with a design agency every day and every day I hear new complaints about themes and WP...
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #33 on: August 16, 2016, 04:55:15 PM »
AMEN, you said it just right Arantor!  Glad to see you still around here, as much as we conflict, sometimes we also see eye to eye ;)  Cheers, buddy!  TBH, I never looked at your Simple Desk code, but I knew if it was built from Arantor it was a fine piece of software.

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 54,072
  • Gender: Male
    • Kindred-999 on GitHub
Re: loadPartialTemplate function Please?
« Reply #34 on: August 16, 2016, 06:39:33 PM »
Actually, a fe wof Bloc's themes allowed changing the placement of some of the blocks by choice...
banner, menu, news

several of the portals allow moving blocks around...

so, it is possible, even in the SMF theming system
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #35 on: August 18, 2016, 09:39:00 PM »
Hello Kindred, nice to see you still around.  Thanks for your input, but that's not exactly what we are saying here.  Basically there needs to be some easier way to manipulate the content in the themes that come bundled with SMF (and, also, any theme that gets installed).  Creating new theme files is not a good alternative, because it does not change the default file(s) (Theme that's installed).  Creating your own theme, now makes it more work.  There simply needs to be an easier way to do this.  I mean, there is much easier ways out there already with other platforms.  This is why my initial thought was to integrate Theme hooks with SMF, which I still think would be a good idea to hook your code into any theme automatically.  Adding functionality within a theme without editing the files of that theme.  I mean, I never did like doing theme edits to the Default theme and the Core theme for my mods, only to find out that the next version of SMF added a tab or a space where I did my replace/after/before at.  Anyways, was just a thought...

Quite frankly, I feel like doing edits to theme files is a bit sloppy nowadays.  It's kinda like building a website with HTML only where you have to do a million and 1 edits to a million and 1 files...  I feel like this can be handled better, that's all.  Cheers :)
« Last Edit: August 18, 2016, 09:49:24 PM by SoLoGHoST »

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #36 on: August 18, 2016, 10:42:19 PM »
Maybe SMF does not want to allow something like this because they want to keep template and source separated, but this does not have to be the case, and it can still be handled in a very clean and productive way...

For Example:

Wordpress does it a few different ways, but wordpress has built-in functions for allowing this also, with any plugin/theme, which SMF does not.

Such functions are as follows:

Filters:  Allows the content/variable to be changed by any plugin... by passing in the first parameter to the filter function with priority...

apply_filters, add_filter, remove_filter, has_filter

Plugins can than do something like this:
Code: [Select]
echo apply_filters('my_filter_that_can_be_modified_by_any_theme', 'Default Value');

Now it will echo 'Default Value' if no filters exist that change this, otherwise, if the filter exists, it can be overridden...
Example:
Code: [Select]
add_filter('my_filter_that_can_be_modified_by_any_theme', 'another_function', 10, 1);
where 10 = priority, and 1 = parameters that get passed into the function_name.  Than anything (theme or plugin) can now manipulate the filter, like so:
Code: [Select]
function another_function($echo) {
   return 'Something Different'; // This will now replace 'Default Value' in that theme/plugin
}

Actions:  This is geared more towards simply outputting html for the most part.  This is not really a means to manipulate the original content, as it doesn't really get called to return anything...  For example:

add_action, do_action, has_action
Code: [Select]
if (has_action('my_plugin_action'))
    do_action('my_plugin_action', $param1, $param2);
And in the main plugin/theme file:
Code: [Select]
add_action('my_plugin_action', 'my_function', 10, 2);

function my_function($param1, $param2)
{
    echo '<div>Here is some content</div>';
}

Anyways, those are 2 examples.  The Wordpress Themes would than have do_action() in multiple spots where actions can be overridden, and apply_filters() in other spots where variables, etc. can be overridden.  If the default theme was built in such a way, other themes can mirror it and SMF I think would be a more productive forum platform, that can be made into something much bigger than what it is now.  Anyways, I'm just passing on what I know... do with it what you want.  Don't take other code, but make it something unique to SMF possibly?  It's the meaning behind the code that's important here.  SMF has done an amazing job already with the hooks in Source Files, but there is very little to no support to tie into Themes, and there needs to be IMO.
« Last Edit: August 18, 2016, 10:53:11 PM by SoLoGHoST »

Offline Kindred

  • The Mean One
  • Support Specialist
  • SMF Legend
  • *
  • Posts: 54,072
  • Gender: Male
    • Kindred-999 on GitHub
Re: loadPartialTemplate function Please?
« Reply #37 on: August 18, 2016, 11:07:26 PM »
However... Wordpress pretty much sucks.  So comparing simple machines forum template design to Wordpress design is a poor choice.

We have worked very hard to separate functions from display and going backwards if not going to happen.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

Offline SoLoGHoST

  • SMF Hero
  • ******
  • Posts: 1,791
  • Gender: Male
  • Real coders do not need to comment their code!
    • Dream Portal
Re: loadPartialTemplate function Please?
« Reply #38 on: August 19, 2016, 12:20:22 AM »
Ok, to each their own.  I'm not trying to push this topic on anyone.  Just thought I didn't explain myself good enough last time.  Wordpress does not suck, but that is your opinion.  And I'm assuming that you are making an opinion based on Experience?  My opinion is Drupal actually sucks as a CMS, cause it's unstable, and my experience with it was terrible.  SMF is a good software, but can be tough to work with because it being too STRICT on certain aspects that it need to be LOOSE on for a site to be flexible and valuable.  Developers will recommend the flexible choice with the most room for expansion to their Customers.

On another note:  I feel like I am constantly missing my target audience here.  The target audience I hope to achieve with my replies in this topic are open-minded individuals with the ability to understand the meaning of an analogy, and not take it so literal.  To say that is a step backwards, when over 74 million sites are depending on Wordpress and 29,000+ WordPress Plugins exist, 46 Million+ Downloads, over 18% of all sites on the web powered by Wordpress, well... they must be doing something right (And these are statistics from 3 years ago).  I'm sure you have nothing but good things to say about SMF, and that's all good, but there is an EVEN BIGGER picture.  Nuff Said.
« Last Edit: August 19, 2016, 12:47:19 AM by SoLoGHoST »

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 66,703
    • Arantor on GitHub
Re: loadPartialTemplate function Please?
« Reply #39 on: August 19, 2016, 12:46:34 AM »
And suddenly your argument ceases to make sense.

WordPress is better because more people use it? Sure more people use it, it's not a tool for serving a specific technical need. You're comparing it to SMF like you could compare a screwdriver to a plane (the woodworking kind) and go "more people use screwdrivers", which they do because it is a general purpose tool... Wordpress is a general purpose tool, SMF is not, it is therefore shocking that less people use SMF. SHOCKING.
To assume is to hope that those who came before had the presence of mind and capacity to implement the dreams of those who would come after.