Magento - adding getChildHtml() to existing template as part of module - magento

When creating a module to extend magento its great to be able to package everything up in a self contained, well, module, and simple add it to a site by dragging it in to the root directory.
I have one problem though, what happens when you create a module and need to add something to output in an existing template file say catalog/product/view.phtml for example.
This is fine when you are in full control of the code and have easy access to it, you simply use a layout update in your modules config file, add the necessary code the your modules layout file and then call getChildHtml in the desired template.
But, I am creating a module that collegues will be using, now and in the future and it would be good to have a way where they dont have that final step of having to manually edit the template file.
How do you get around this instead of completely replacing the template file as part of your module?

David,
Though I haven't tried it yet myself, Inchoo is a fantastic resource, and they posted this article earlier this year and it looks quite intriguing and could potentially do what you want to do without needing any template files: http://inchoo.net/ecommerce/magento/how-you-could-build-your-magento-extensions-without-view-files/
Otherwise, there's no really nice way to do it (that I know about at least). You need to do as you said and create your own layout xml file, and override the template with your own.

Related

auto linking asset files, laravel

I'm pretty new to laravel and so far I'm liking it. Due to some situations where I forgot to include my new js or css files into my layout, Im looking for a way to link all files from those folders.
Im totally willing to create this myself, but I'm not sure what is the best way to do this. So far I have registered some serviceproviders, like viewcomposers and helpers. I was thinking I can make another viewcomposer which collects the folders I want, and link it to the desired layout.
But I don't want to create unnecessary functions (which might already exist). I'm hoping you guys can give me some insight in what's possible in laravel, good/bad practice, useful classes to use etc.
I wouldn't do this.
I would use Elixir (depending on which version of Laravel you are using) to compile and version my assets. This will mean that you only need to include the references to one file CSS file and one JS file in your view.
https://laravel.com/docs/5.3/elixir
You then just need to maintain your gulpfile.
Versioning your assets also means that you never need to CTRL+F5 to refresh them.

Core Data "Codegen" for existing project in Xcode 8?

So, I understand that Core Data's new "Codegen" feature puts class files into "Derived Data" instead of your project... which is nice.
However, recently in the past it created two separate classes... one that you could manually delete and regenerate, and another that could contain your code/methods for those objects.
I tried turning "Codegen" but it doesn't seem to create the file for our code. How is this supposed to work if we want to add methods to Core Data objects? — Does anyone know how to get it working like before, just without the extra duplicate files, or is there some reason we shouldn't be doing that?
If you want to add your own code to the class then just set the Codegen dropdown to Category/Extension and it will only generate MyClass+CoreDataProperties.h and MyClass+CoreDataProperties.m into Derived Data, which you then need to include at the end of your MyClass.h header file, like before.
btw; it can be a bit finicky getting it to work properly as this setting sometimes doesn't save after you change it, so try save manually before you go to another file and then check the setting saved after. Also clean your project before you build or it might not generate the files.

Magento - Rewriting Templates: Alternative Approach?

After searching for articles regarding template rewrites, I've done a successful one written on the article here.
However, as stated in the article, one would have to copy the contents from the original .phtml file to your custom .phtml file. This is where the problem lies -- since we're a team handling different modules at a time, it may come to a point where they would need to overwrite the .phtml file I've written and do the same process -- copying the contents from the original (Which in this case, should be my custom .phtml) to their custom .phtml, which isn't upgrade safe at all because any future changes that I make on my module will not reflect on the template as my colleague has already rewritten it.
Would there be another approach for this? Or would the only way around this is to merge our code into a single custom .phtml file?
One possible solution is to modify HTML via Magneto event core_block_abstract_to_html_before.
So that multiple modules can add modifications upgrade safe.
Downside is using regular expressions or xml changes in the code, not in the templates.

How to add files to a PrestaShop theme without "hacking" the core

I am working on an web built in PrestaShop that needs some re-design. I have made a copy of their theme and I am working there. Now I need to add some javascript files and they need to be included in all my theme pages.
I have read similar questions here and looked for info and basically I have found two solutions proposed:
1) Add the file directly into your HEAD.tpl using something like {$base_dir}
(explained here: Prestashop root directory)
2) Add the files in the FrontController.php (overrides/classes) with a new setMedia() function
(explained here: http://tinyurl.com/cxucwq7)
The second solution seems the most recommended one but when I open the FrontController.php I see the following warning:
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer versions in the future.
So I'm a bit confused now. Is it safe to edit this file? How about future upgrades, will they overwrite any changes made there? Isn't it safer to add them to your themes header.tpl and not affect the core of the cms?
(This is my first question here, I tried to follow the guides but I would appreciate any comments on how can I improve it, thank-you!)
It is totally safe to use the override file, and that's why they exist. I have used them in every Prestashop I made and they've never had been replaced in an update. The text they put is for the license, they probably just copy/paste it everywhere.
I wouldn't recommend manually adding the files to the header.tpl. It will work, but the advantage of adding it with the Tools::addJs() method is that the script will be concatenated with all the other scripts.

Adding syntax highlighter to JamWiki-1.2

The tutorial http://sinnerinc22.blogspot.de/2010/07/adding-syntax-highlighter-to-jamwiki.html describes how to enable syntax highlighting in JAMWiki.
My problem is that in the recent version of JAMWiki v1.2 the two files to be modified WEB-INF/jsp/top.jsp and WEB-INF/jsp/close-document.jsp do not exist any longer...
There is a third-party syntax highlighting tag extension available with JAMWiki 1.2 link that may work for you
I have added SHJS to my installation just following SHJS instructions rather than JAMWiki instructions. Simply edit JAMWiki JSP pages to add content as documented here. To see how does it work, look into the source code of this HTML document.
You even do not need to compile anything after you edit JSP, the server does this for you automatically.
Following up on Audrius's answer, here's exactly what you need to modify.
./jamwiki.war/WEB-INF/jsp/topic.jsp Modify it to look like this
Download the SHJS zip and copy all of the individual files from ./css/, ./lang/, ./sh_main.js, and ./sh_style.css from the zip to JamWiki.war/shjs/. (This will flatten the directory structure so everything is now in ./shjs/. Flattening the structure is optional but it makes for easier paths when referencing them in the jsp.)
You can modify the .war with 7zip or dig into your web app container file system and place the JSP and shjs folder directly.
Redeploy or refresh as needed depending on your preferred edit method.

Resources