Question About Custom Symbols
Posted
#4835
(In Topic #1059)

Standard member

(that I think I know the answer of!)
For the longest time I've basically duplicated the original contents of symbols.php and added my custom symbols to the end of that file, then just uploaded it in the sources_custom directory. Then it occurred to me, "what happens when Composr upgrades change the contents of this file? Do I duplicate the new version of this file and add my custom symbols to the end every time a new version comes out? If I don't, does Composr ignore the new updated file in the sources directory since I've got a custom one?"I don't know a lot about Composr on a programming level, but I know a little. I figured out how to do simple additions and create a couple basic custom symbols - but the topic of creating custom versions of files (and placing in the *_custom folder) and which one of those files Composr "ignores" has always confused me. So I did a small test…
I left the original symbols.php file in its original directory, under /sources/. Then, I added ONLY my custom symbols to a new symbols.php file and uploaded that to the custom directory. This way, I could get updates of this file when it's changed in future versions of Composr without the need to keep going back and add my changes to the new version.
The test showed that not only does Composr read the original file, but it ALSO reads the custom file. So all this time my Composr site has been reading both, and in a sense all the symbols were duplicated twice. I've had my fare share of bugs with Composr, but that makes me think – "could that have caused an issue in itself?"
Anyways, I know it's not the same for templates – at least I'm 90% sure of that. Correct me if I'm wrong, but if you've got two template files with the same name; one in the /templates/ directory and one under the /templates_custom/ directory, Composr doesn't read both of them. Rather, it prioritizes the one in the custom folder. Oddly Composr doesn't share that same functionality with PHP files – which is a good thing for me. I just hope my solution doesn't cause even more harm than good - so far my custom symbols file (which only contains 2 custom symbols) in addition to the original version of the symbols.php file, both seem to be recognized without issues.
Posted

Site director

That makes sense for PHP files, as they consist of a set of functions/classes. For templates it would make no sense.
Language ini files support merging too, although it's much more straight-forward.
Become a fan of Composr on Facebook or add me as a friend. Add me on on Mastodon. Follow me on Minds (where I am most active). Support me on Patreon
- If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
- If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
- If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
- If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Posted

Standard member

For symbols, I create a symbol hook. Instead of modifying the symbols.php file or overriding it, I create a separate file (for example, MY_SHINY_NEW_SYMBOL.php for a {MY_SHINY_NEW_SYMBOL} symbol) and drop it in the sources_custom/hooks/systems/symbols directory (create it if it doesn't exist in your directory structure). I would hope nobody would submit an addon that had a symbols.php override in it. But if someone did and you installed that addon, I believe it would overwrite your custom override.
Check the github repository to see how the symbol hook files are structured (https://github.com/ocproducts/composr/tree/master/sources_custom/hooks/systems/symbols). It's really simple to take an existing symbol hook file and use it as a template for your own symbols. Just change the file name to, for example, MY_SHINY_NEW_SYMBOL.php. Then change the class definition to Hook_symbol_MY_SHINY_NEW_SYMBOL (using my example of MY_SHINEY_NEW_SYMBOL.php symbol hook file). Then change the run function to include the code needed for the symbol. Anything returned at the end of the run function is what would be sent to the template when the {MY_SHINY_NEW_SYMBOL} symbol is called.
Regards,
Jason
My ocPortal Sites: Holleywood Studio / Tech Fusion Online
My Composr Sites: NEWBotics Labs
Jason
My ocPortal Sites: Holleywood Studio / Tech Fusion Online
My Composr Sites: NEWBotics Labs
1 guest and 0 members have just viewed this.