I need to insert a URL/button in every article but I need to do this from a specific component, without modifying the existing Joomla components. I need somehow to override the content output and append the necessary elements.
Is this possible?
This is a good place to start - https://docs.joomla.org/Plugin/Events/Content
If you look at the examples it will show you how to write a plugin that can hook into the content a certain point and manipulate it as you see fit using one of the listed functions.
I would put a conditional statement in the hook to find the parameters that match my component and then output my url/button when the condition is matched.
Related
I am using php framework laravel and I would like to implement shortcodes.
Does anyone have a suggestion how to go about implementing shortcodes that could be inserted by user into a page or blog post.
Example, lets say I would like to have a shortcode for gallery that has some images, something like
[gallery=id]
which would then display that particular gallery. Ofcourse I have gallery model and gallery & images tables.
My first thought is that I would have to scan the content of the page/post and look for shortcode and when I find a particular shortcode, then what? What do I insert instead of it?
I can't insert php code that loops through the gallery and produces output. I guess the best way to do it would be to run a function that returns complete html code that I insert instead of the shortcode.
Is it possible to return a view from a function and insert the result into a page/post?
Depending on what kind of "shortcode" you want, there are numerous options here:
Blade Directives
Blade Layouts
Blade Sub-Views
Blade Stacks
To be clear, I'm assuming you want to insert this into content blocks stored in a db or something, not in your exiting view files.
Assuming you want inject the text into your view for display, you could allow content creators to use a templating format like mustache (https://en.wikipedia.org/wiki/Mustache_%28template_system%29) with server side callbacks/helpers/partials (in the view) to populate your own custom tags with dynamic content (gallery links in this case).
Main Points
I'd stick to a basic well known templating format like
mustache for this. In laravel, allow to Blade templating notation, it sounds like you want for this case to register a Blade::directive: https://www.laravel.com/docs/5.3/blade#service-injection.
I'd try to use an existing library if one such exists before
attempting to create your own short-tagging markup parsing /
callback paradigm. Blade has functions and methods handle such callbacks.
#2 is not necessary, but highly recommended, but #1 should be considered near religious.
UPDATE: as point out in other answers, Laravels built-in templating Blade, has this functionality, so stick to it's format and functionality.
Here's my suggestion (in pseudo-laravel/php):
Assume your marked up content from model pulled into the controller is in $content['blade_markedup_content' => 'here is my new gallery: #gallery(1)'] to be passed to the view.
Add a Blade directive #preprocess() to and in the template/view use <p>#preprocess($blade_markedup_content)</p> in place of just substituting raw <p>{{$blade_markedup_content}}</p>.
In the respective callback function for the #preprocess() directive
Instantiate a new $my_compiler = new BladeCompiler();
Register to this new blade compiler directives to handle the like #gallery(1) you put in your blade_markedup_content
return from the #preprocess() with $my_compiler->compileString($blade_markedup_content);
Viola... In theory, this should result in a parsed and substitute string from #preprocess($blade_markedup_content) in the original template.
I'm creating a website with CakePHP; the problem now is that I want to show in the website footer (that will be visible on all the pages), the result of a query (e.g. "Most popular products").
What is the correct way with CakePHP to achieve this?
At the moment I created a mostPopularList() in my Product controller and a most-popular-list.ctp view that only outputs an <ul> list, thinking that then I could include the output of this file in my layout (default.ctp), but I didn't find the CakePHP way to do that.
Thanks!
Use a view cell or call the query in the AppControllers beforeRender() callback and set it there to the view. Taken from the documentation:
View cells are small mini-controllers that can invoke view logic and render out templates. They provide a light-weight modular replacement to requestAction(). The idea of cells is borrowed from cells in Ruby, where they fulfill a similar role and purpose.
View Cells
Controller::beforeRender()
If this is needed on really every single page I would probably go for the beforeRender() callback, easy to do and change globally.
What I'm trying to do is to add some HTML tags to my Djimageslider's slides titles in joomla 2.5. I will need something like this
something <b>more</b>
but when I click on save or apply then its remove all HTML tags.
I've check the administrator/com_content, which I think should be responsible for inserting the database data, but I couldn't find the answer there.
Can anyone help me with this headache?
The form inputs are "cleaned" by default and you want to tell Joomla not to touch its contents.
Find the component you are using in the url (option=com_djsomething?) I doubt it's com_content.
Once you have the component, you have to find where the form is defined.
The task in the url may help, also the view if it's there. The form can be declared in one of two ways:
by providing an xml manifest, which would be located in the component's folder /models/forms
by inserting it in code, which could be in the component's folder /views/view_name (the default view name would be the component's name, but this can be overridden in the controller so look around).
In both cases, you should be able to find the line that corrensponds to your input, and specify format="raw" as a filter.
Check http://docs.joomla.org/Text_form_field_type for syntax help of the xml manifest, or search the docs for the right JElement in code
The format parameter is optional, if it's not there just add it. Besides "raw" there are other filtering options available, make sure you do filter out undesired input and sanitize your inputs before saving to the db (use $db->quote() to insert field values in the query)
i have a comments section that gets called at 3 place in one place along with posts and at other two places solo.(comments only). Now using this as a element makes sense. But my posts are also rendered via a element. Does it makes sense to render a element inside another
Here is the answer:
// Render the element in /View/Elements/ajaxreturn.ctp
$this->render('/Elements/ajaxreturn');
http://book.cakephp.org/2.0/en/controllers.html
There's nothing wrong with doing this. No clashes are going to occur as the variables are scoped
http://book.cakephp.org/view/1081/Elements
Since version 2.1 you may embed one view into another by "Extending Views"
$this->extend('/Common/view');
(documentation)
Since I knew about the elements I try to use whenever I can. They help you to minimize the code repetition. It's not unusual include elements inside another.
In fact, I use the same structure in the elements directory as the views directory to organize them.
I assume that the 3 places you mention are handled by views no? So if you have a posts element and a comments element you can include the elements needs according to the view no? In one view you only use the comments element and in the other you only use both elements what do you think?
Views - Fields: I want to remove a certain matching word from a returned string by using the "Rewrite the output of this field". Is there extended syntax for this or is there a way to use php string-functions/regex in this field?
Don't believe you can do anything more than put in HTML, text, and other fields in there. You'd probably be better off using something like the String Overrides module or some good old str_replace in a custom module or theme preprocess function.
EDIT: Found a really easy solution. First, install the Views Custom Field module. Then add whatever field you want to modify to your view, and check to exclude from display. Then, add a Customfield: PHP Code field after that and add whatever processing you want to that. You should have access to the original field in that PHP Code field, so you'll be able to process it from there.
Good question, and I hope this helps!