CodeIgniter template engine view syntax {} - codeigniter

I have CodeIgniter project and need to change view. there is unusual way to display content in view. It doesn't use any loop. Instead of it is written, like this:
{news}
//Some html code
{/news}.
Do anyone know what template engine does it uses? And how it works?

Related

How can I display an XML feed without any template code in Joomla?

I'm trying to display an XML feed in a custom Joomla 2.5 component's view/layout, but the XML is rendered as a regular layout inside the site's HTML template. How can I display the XML without any template HTML code?
(The trick to include tmpl=component in the URL from this related question doesn't help, there's still some HTML output from the template that ruins the XML.)
I would prefer a solution that only involves code changes in my custom component, like in Symfony when you call the method setLayout(false).
The only solution I have found is to create a file in the current template folder, e.g. "xml.php", and put only this in the file:
<?php
$document = JFactory::getDocument();
$document->setMimeEncoding('text/xml');
echo '<?xml version="1.0" encoding="UTF-8" ?>';
?>
<jdoc:include type="component" />
Then I can append tmpl=xml to the URL.
[edit]
My bad, I made an assumption and you know what that gets you.
Joomla! 1.6->2.5 you can create an alternate output format for an existing view by:
calling the view with a format parameter attached e.g. &format=json
creating a matching view class file e.g. view.json.php that can sit alongside the standard view.html.php file for you view.
The view.yourformat.php file can use your existing controllers and template files in the normal fashion.
Don't forget to add either &tmpl=component or &tmpl=raw to your query string so modules etc don't load as well.
tmpl=raw won't load the html body surrounds or template, only the main component.
[/edit]
From Joomla! 1.6 onward (including 2.5) there is built in support for controller formats ie. you create a controller for the output format you want.
Normally a controller would be named for each view:
/components/mycomp/controllers/myview.php
A XML version of the controller would be name:
/components/mycomp/controllers/myview.xml.php
A JSON version would be:
/components/mycomp/controllers/myview.json.php
To call a particular format version of a controller you simply add &format=theformatyouwant to the URL parameters, so in your case &format=xml
This is discussed in this document from 1.6 days - I used it as a basis for several of our components that have JSON and ics requirements.
This issue drove me crazy a couple of times.
After much frustration, the simplest solution is the one suggested by cppl. In your query
string put the following variables:
format=yourcustomformat
view=viewname
Let say you want json output from a view called json.
Create a veiw folder with the name of your view
json
And a file inside that folder called
view.json.php
Then in your url string you include the following url parameters seperated by the & symbol:
index.php?option=com_mycomponent&format=json&view=json
cppl is correct that this loads a non-html view. However you don't have to put the tmpl parameter in at least in 2.5. If the view name is not view.html.php then 2.5 seems to not include the assigned site template in the response. I think because the view is not veiw.html.php it assumes raw output and does not include the template. I tested this with both an ajax call and a direct url call to the view and in both cases all I got back was the component output. Yeah!
If someone knows where this issue is well documented by the Joomla folks please post!

How does Orchard get away with no call to RenderBody?

I’ve been dissecting the Orchard CMS rendering and view engine in an effort to understand how it’s put together. I have discovered that neither RenderBody nor RenderSection are ever called. It is my understanding that the Razor view engine requires a call to one or the other.
What is it that gets around the requirement that RenderBody or RenderSection have to be called or an exception is thrown by Razor?
Is it the fact that there’s a custom view engine (ThemeAwareViewEngine)? If so, how does it handle parsing Razor syntax to generate the content?
Thank you.
It's actually the other way around. Razor itself doesn't require that RenderBody be called it's the RazorViewEngine that has this requirement. There can definitely be another view engine that uses Razor that has a completely different way of working. Take a look at https://github.com/Antaris/RazorEngine or https://github.com/Buildstarted/RazorSharp I've also written a markdown view engine that uses razor for some simple layouts.
From reading the source it looks as if they've created a few custom view engines. Their RazorViewEngine replaces the base class for razor generated files with their own custom WebViewPage which has a method Display of which Zone is an alias for. This is what allows them to render child views in addition it seems as if there are several types of Zones within the LayoutAwareViewEngine such as DocumentZone, ContentZone and so forth.
So in the end they've done a lot of custom code.

joomla add view into another view

Im using joomla MVC and I want to build a form that has different tabs which are different sections of the form with inputs in it. There are some tabs that are common to other forms that I need to include.
I would like to be able to load this common content from a separate file or view so i dont have duplicate code, plus is easier when I need to do a change to the form so I dont have to do it in all the forms. It's like displaying a view inside another view.
Is there a way to accomplish this?
A Joomla! provides the loadTemplate method to views.
So if you're currently in a tmpl file loaded for layout edit (ie. tmpl/edit.php ) you can call $this->loadTemplate('tab1'); and Joomla! will load the tmpl/edit_tab1.php file in the same view as your edit.php.
In that same view if you wanted to include say tmpl/other_tab1.php you would have to temporarily set the layout to other, eg. in one of our components during the Run template we need a tab from the Edit template, so we use:
<?php $this->setLayout('edit'); // This is ugly
echo $this->loadTemplate('plan');
$this->setLayout('run'); ?>
To load a template from another view alltogether, I think you would have to temporarily over-ride the view value, load the template then restore the view. eg.
$jinput = JFactory::getApplication()->input;
$jinput->set('view', 'other');
$this->loadTemplate('tab2');
$jinput->set('view', 'original');
NB: this last bit I haven't had time to test but it should work.
You can load a different template file for a different view manually, by simply requiring it. The following is for a view called "nameofotherview" with the layout "layoutname". If this is for an admin view use JPATH_COMPONENT_ADMINSTRATOR instead.
require(JPATH_COMPONENT_SITE . '/views/nameofotherview/tmpl/layoutname.php');
Remember that the data set up in the view class needs to be compatible with the main layout as well as the layout you're loading from elsewhere.
A side effect of doing this is that template overrides won't work. The loadTemplate function is doing a require but it checks the template paths for overrides first.
You can use vews in other views as described in Joomla documentation: Sharing layouts across views or extensions with JLayout

HTML in public folder with hooks

I have an HTML file (index.html) in the public folder.
These HTML has some "hooks" in it.
Like:
<div>{client_ssnumber}</div>
<div>{client_company}</div>
I have to retrieve this file and complete the information in the hooks using data obtained in a controller´s method, then display in the screen.
What is the rails way to do it?
You can't do this (without terrible terrible hacking), it's hard coded to look for public files before checking the router.
Anyway, Your client is wrong. Tell them to use "<%= ... %>" instead of "{ ... }" and move it into a view (you should move it into the view, so it's where you want it to be, then just tell them what the name of the file is).
There is no sensible reason to make up your own templating language. It will be buggier and slower, and it will add a lot of time to get the product out the door. Plus you'll then have to maintain that code. This is a solved problem, use ERB. If they really like that syntax, use Mustache which is pretty similar, and is an existing templating language.
If you can't get them to do this, you have much bigger problems than how to render this page.
Put them in a view, on app/views/ and use a template engine like erb or haml. You can then assign variables in a controller and use them in your view.

MVC for a CMS? What about themes?

I understand what is MVC and CMS. I understand MVC pattern and how CMS should working. But I have problem with theming and the pattern.
Example:
When CMS is installed on serwer I want to change my homepage. I want to display some additional data. I change my homepage template and add a function call to pull data from DB. My new data will be displayed on my homepage. :)
But when I do this I broke MVC pattern because in this situation View decide which data should be read from DB to display on my homepage.
So... is it MVC for a CMS? Or maybe it shouldn't be a clear MVC pattern to work with situations like this? Maybe I should forget about patterns? I'm confusing...
PS
Wordpress it's not build on MVC pattern, I guess?
Design patterns like MVC are meant to be about separating your display code from the business logic, etc. This makes it easier to change any part without affecting any of the other parts (eg. change the templates without having to worry about accidentally changing any business logic).
You situation sounds like the function you are adding is simple view logic? It might be best to put the function into a Helper and have the helper call for the data through a Model. Then, in your view, just call the Helper.
In pseudocode:
Helper
function get_whatever_data () {
// get the actual data from the model
return SomeModel.get_the_data_thats_needed_here()
}
View
<div id="some-id">
<? print get_whatever_data() ?>
</div>

Resources