I need to add this code to Joomla please
$(".item-204").append('<ul class="nav-child unstyled small"><li class="item-205"><a href="index.php?option=com_content&view=article&id=9" >رؤيتنا</a></li>');
what is the best way?
One way to do this would be to use Regular Labs ReReplacer which could be set up to replace the .item-204 code with .item-204 plus any additional code you require. I am assuming .item-204 is unique on the page.
The advantage of using this extension is that you don't have to find or update the core code. Updating core code is often considered bad practice as any future template or extension updates can undo your changes.
It's really just about adding this code to every page? Instead of adding another plugin so your site you can put your code in a script tag located in your templates main php file. This file is named index.php and is located here: /templates/[your template name]/index.php
If you want to do it even better, place this code in the templates JS file. Some of them have a file like /templates/[your template name]/js/custom.jswhich is a good place to add custom JS to.
Related
I have been trying to search a solution online and on stackoverflow but did not come across any satisfactory solution.
I wanted to know how can i include (if required) header.php and footer.php automatically in the new PHP pages that i create, at present whenever i create a new PHP file i manually add header.php on top and footer.php at the bottom, I dont really have a problem with doing this but i was wondering if this is how everyone does it and if not what is the best solution to this.
I know I could takeup any framework out there and use that because may be they include the header and footer automatically, but i am referring to custom PHP coding.
I will really appreciate views of experienced developers out there.
The usual approach is to use the front controller design pattern.
Use a single PHP file to load all the pages. Have it include the header and footer and use the URL (and whatever other information you like) to determine which content to include.
PHP developers often use mod_rewrite to map URLs onto a single script. You could also use the Apache alias directive.
I'm migrating my blog from wordpress to datalife engine. For what i figured it out by searching, is writen in smarty php... I never worked with it before and i want to query the database to implement something on the theme... But i can't write it on the tpl files...
What i want to know is, where are functions like {rating}, {content} or [related-news] declared...
i want to query the database, but for what i know, i can't do it on the tpl files direcly.
And i can't find any info where they are because all the readme files of datalife are in russian. Can someone help me to figure out how is this structure done?
Datalife Engine use the module files in folder /engine/modules/ to define which .tpl files to use for which function, so there is no single file that declare all tpl files, you have to check which module or which function you want to edit, in your case it seems like you are looking for full page of content which in DLE called "fullstory" the module that handle this module is engine/modules/show.full.php and the theme file to use for this module are fullstory.tpl to dispaly the rest of fullstory, addcomment.tpl for add comment form and relatednews.tpl to display related news, about {rating} there are at least 3 modules use this tag which are show.short.php, show.custom.php and show.full.php, however the DLE structure is each module use its own tpl file to display as {content}, I think if you go to dlestarter.com you can get all answer you need from them, I think they are not so advanced team but they do speak English so they can help you more effectively to any questions you may have...good luck!
Datalife Engine does not use smarty template engine!.
It has it's on custom engine.
The Flow of the cms its simple, every article has a short story and optionally a full story.
In the template folder you have a bunch of tpl files with build up the final page.
main.tpl beeing the file called for every page you display.
Now typically once you call the front page the main.tpl along with shortstory.tpl are called along with other blocks for the front page.
the shortstory.tpl is build by the /engine/modules/show.short.php file witch will call the db for the data or memcached if enabled and the data was cached replace the the engin tags with the necessary data like {title} and many others.
You should really look at the documentation to undestand witch tags are found in witch section.
One important think to note is that you cannot add php in the tpl files at least not out of the box but you can include files with php in them.
I recommend heading over to dlestarter.com they are a good reference for documentation in English and pretty much the only once as well. They also have a forum where i look into sometimes.
I am creating a storefront for a client using Prestashop. Prestashop uses Smarty .TPL files. I read through smarty documentation and scoured the web but all of the suggestions are not working.
I first made a site using regular .php pages and I am including the header.php on every page.
I then made a directory for prestashop and got it set up. I edited the header.tpl file and was able to hard code in the header.php code. The problem with this is; when I want to edit the header (nav bar, images, social media), I will have to edit it in two different places. So I tried to "Include" my header.php file.
Though, when I try using smarty's {include_PHP "file.php"} and/or {PHP}include...{PHP}, Prestashop errors out and gives me a blank white page - no errors are given - (in chrome it gives me a "server error") until I take out the includes.
I tried replacing the entire header.tpl code with a smarty include and another piece of code that had a header hook, but none of these worked. Any suggestions? I just want one header where I only have to edit it once to make changes.
Using Prestashop v 1.4.4.0
Edit: I changed allow_php to true from false. Now it's trying to add the file, though it says it can't find the file. I placed it next to header.tpl and just used:
{php}
include('navBar.php');
{/php}
ANSWERED!
When using Smarty .TPL files, when you include something, you are not including from the path of the file you are working on. You are including from where the index is.
Example:
I am working on header.tpl, this is located in:
siteroot/smartyinstall/themes/themename/header.tpl
When the include is looking for the file, it is actually looking for it in the smarty root folder because the header.tpl is being pulled into the index.html page that is in the smartyinstall folder.
So, you have to go from there. In my case, the header that I was trying to include was in:
siteroot/includes/navBar.php
so, I had to write include('../includes/navBar.php');, only going up one directory, instead of four.
I hope this helps everyone that has a problem like this!
It's considered very bad practice to include php in smarty .tpl files so I would strongly recommend you don't add code this way. One of the main reasons for disabling the {php} tag is to help prevent code injection attacks. eCommerce sites are by their very nature natural targets for exploits.
A better approach would be to override the FrontController class to assign your custom code to a smarty variable - this could then be inserted into the header.tpl without resorting to using a php include().
With the class and controller overrides available in Prestashop 1.4.x there's no real reason you should need to resort to hacks and/or modifications to the core distribution.
Paul
I have a medium size legacy php application with almost no javascript integration. I've recently been learning javascript (yes actually learning it) using Douglas Crockfords excellent book and taken YUI as my library of choice. I've tried out a few things and got a few things working but now I want to integrate the various components etc into my application properly, my question is how to go about doing this for ease of maintenance and code reuse.
Currently the application consists of
php pages
smarty templates (html templates with some special template markup) for each section of a page so multiple templates may be used for a single page.
single css file.
I have the following ideas about how to integrate my javascript into the pages.
Write inline javascript in each smarty template with the code required for that section.
Write a seperate .js file to go with each smarty template that is linked in and then a single inline script to run it.
a seperate .js file for each php page which would have all the functionality required for the entire .php page. A small inline function would call whatever functions were required.
Something I havent though of?
Does this make any sense? Does anyone have a good suggestion for this?
Update:
One extra bit of info is that its an internal application, so its not so important to restrict everything to a single file.
Two other options:
A single JS file that contains all the JS for your entire site. Depending on your caching settings, you should be able to get the user to download just one file for the entire site and use a cached version for every other page.
Divide your JS up according to function, rather than page, and include whatever functionality each page requires. E.g. one page may require tabs, form validation and animation, while another may only require tabs.
Or you can have a hybrid of these: one JS file that contains the vast majority of your code and an extra file if needed for particular pages or templates.
None of the approaches mentioned are wrong (though I'd skip the inline JS one as much as possible); which one is best will depend on your precise situation and your personal preferences.
Firstly, most setups allow a master layout template in which you can place a common page opening or, alternatively, each template includes some global header.
That being said, you should do a combination of 1, 2 and 3:
Have a .js that is included in all templates that contains global functionality. Each template may also optionally have it's own .js specific to that page or section of pages. Finally, if there's tiny amounts of code specific to a page (or must be dynamically generated each time), it won't make sense to initiate another http connection for it so have that source be right in the template.
if you don't have a ton of javascript then create an external js file and include it in the header of the webpages and be done with it.
Often times, when I try to add my own custom PHP source codes to the template files (sidebar.php, index.php, header.php, etc...), it generates errors. However, it works properly on it's own outside of Wordpress. Is there a way for me to use my custom PHP stuff in Wordpress' template files?
If you're talking about the sidebar.php, index.php and header.php in wp-content/themes/themename/, well, of course you can edit these files. They are meant to be edited. Only make sure that you don't overwrite existing PHP functions...
You can read about that on Wordpress' Docs
No plugin required to add your own php, but to maintain upgradability you should, as far as possible, avoid altering core WP files and place your code within your own theme's files or in your own plugins. If you're getting errors it's hard to guess at what they may be without details, but I've found that, apart from simple parse errors etc., the most likely causes are scoping errors.
With Wordpress you can extend Wordpress functionality by writing your own plugins. This is a fairly pain free process.
http://codex.wordpress.org/Writing_a_Plugin
You can also extend the functionality that templates have by putting functions into the functions.php template file.
http://codex.wordpress.org/Theme_Development#Theme_Functions_File
Adding custom php code to templates shouldn't generate errors. The only problem you might be having is that your code is conflicting with existing wordpress function names and variables.