echo modules::run() in html jumps before doctype - codeigniter

I'm using HMVC and calling modules in a view. In some cases however, the modules appear before the Doctype! It seems to be caused by calling more than one module into a page but i have instances when i have done this without this happening.
i'm parsing the modules I want to display from the controller into the view
like:
$data['modules'] = array(
'controller/function',
);
$this->load->view('page', $data);
then in the view
foreach($modules as $module){ ?>
<div>
<?php echo modules::run(module); ?>
</div>
<?php }
these divs print fine, and remain where they are supposed to, but for some reason the module jumps before doctype. I've checked that all divs in the whole page are closed, for interfering code in the two modules etc but still at a loss
I've never come across this before, can anyone help?
Thanks :)

This is linked to this post and i fixed it by setting the third parameter to TRUE and echoing the view like this
echo $this->load->view('account_managers', $data, TRUE);

Related

Processwire Add css class to page

I there a possibility to add a classname to a page?
I can't figure out how to implement such feature or if it already exists.
I'm using Processwire 3.0.42.
Put something like this in your template where the body is:
<body class="<?php echo $page->template->name; ?>">
That will give your page body tag a class equal to page template name.
You can add a page title in the same way.
<body class="<?php echo $page->name; ?>">
Don't be worried about adding a class to every page. The overhead of doing this is negligible.
If you wish to add a different class you would need to add a field to your template and append it to the code above.
As always in ProcessWire, everything is under your control. Alternatives to #ivangretsky's perfectly good answer would include-
Simply include a conditional in your template file. (This doesn't scale well if you need to add other classes to other pages using the same template.)
<?php
$bodyClass = '';
if($page->id == 1021) $bodyClass = 'my-class';
?>
<body class="<?php echo $bodyClass; ?>">
NB Using $page->id is better than $page->name, for example, as the ID doesn't change while the name could.
You could also add a field to the page template definition. Add a field called something like 'Body Class'. Then use the content of that field in your template file.
<body class="<?php echo $page->body-class; ?>">
This will scale better than my other suggestion, and there are options in the ProcessWire backend to hide or partially hide the field during normal use if you don't want users messing with its value.
One 'gotcha' from the CSS spec to be aware of is that CSS identifiers, including class names and IDs cannot start with a digit, so you cannot just use $page->id.
There are lot of options and it depends on your needs and maybe imagination :-).
You can use page name, template name, page id, or maybe combination.
<body class="<?php echo $page->template->name; ?> page-id-<?php echo $page->id; ?>">
// Output
<body class="your-template-name page-id-1234">
This way you can target template, page, or both.
Or, as mentioned by #ivangretsky, you can add custom field to page. And again, you can combine this aproach with template name, etc.
It depends on your needs and what you want to achieve.
Notice:
Using $page->id is better than $page->name, as the ID doesn't change while the name could. #DaveP

How do I manually theme Views in Drupal 7?

I am new to drupal and I am trying to figure out how to theme Views. I currently have a content type called Category with the following fields:Title, Image and Body. I created a view for the above mentioned content type so that I would list view of all the categories I have created.
To custom theme the view I created a folder called views in my theme folder, and created the following view files:
views-view-fields--plugin-categories.tpl.php
views-view--plugin-categories.tpl.php
views-view-unformatted--plugin-categories.tpl.php
This is what I currently have in my first file:
<div class="<?php print $classes; ?>">
<?php if ($rows): ?>
<div class="view-content">
<?php print $rows; ?>
</div>
<?php elseif ($empty): ?>
<div class="view-empty">
<?php print $empty; ?>
</div>
<?php endif; ?>
<?php if ($more): ?>
<?php print $more; ?>
<?php endif; ?>
</div><?php /* class view */ ?>
Instead of $rows, I tired to use print $field['image'] and print $field['body'] but this method does seem to work. Could you kindly advise on how I could theme the three fields, within categories, displayed using view?
You should name your template like this
views-view-fields--<machine-name-of-your-view>.tpl.php
So I'm assuming from the above that your view is called 'plugin-categories'. An easy way to check is to go to edit the view and look at the URL while you're on the edit page. It should have the format /admin/structure/views/view/YOUR-VIEW'S-MACHINE-NAME/edit, so you can get it from there.
Once you're sure it has the right name, clear your cache to make sure Drupal is picking up your new template. You just need the one above, not all three to modify the output of the three fields in question.
Once you've cleared cache, Drupal should be picking up the new template. You didn't mention exactly what isn't working, just that it's not working, so I wanted to cover the naming and caching, just in case. Now, to output particular fields in this view template, call them like this:
$fields['your-field-machine-name']
So $fields['body'] (I think you're missing an 's')
You should have nothing about $rows in this template! If you have anything about $rows, you haven't copied and pasted from the correct views template. Simply output the fields as you want them to appear in your view, in whatever order you want with the syntax above and put in whatever css classes, etc you want.
Let us know if that works!

Joomla 1.5: $this->countModules returns 1 for Jumi module even when empty

Working on a site in Joomla 1.5! Typically when testing if a module position is empty in Joomla! I'd do something like this:
<?php if ($this->countModules('position')): ?>
BEFORE
<jdoc:include type="modules" name="position" style="xhtml" />
AFTER
<?php endif; ?>
But in my case I have a jumi module that references external source of code.
In some situations it will be blank, which in that case, I don't want the BEFORE and AFTER bits showing either. But whenever I try running the above code, the before and after sections show up, because
$this->countModules() returns 1 instead of 0.
I have "Hide if empty" set to "Yes" for the module, but that doesn't seem to help.
I've even tried setting a return false; on the external source code but that doesn't seem to help either.
Does anybody have any suggestions?
Hide if empty cannot hide the BEFORE and AFTER because it's in the count condition.And BEFORE and AFTER will only hide if no module is enabled for that position. So to hide these you'll have to put this content inside your module.And check the if empty condition.
Let me know if it's not clear.

Codeigniter URL for navigation

I can't figure out how to do the url links.
Basically I have my navigation bar, and I don't know which CodeIgniter URL code to use and how to implement it.
Is what I'm doing here right?:
<?php $this->load->helper('url'); ?>
<li>About Us</li>
I tried to do an anchor like this, but when I load the page it just turns up blank:
<?php echo anchor('views/about.html', 'About Us', title='About Us'); ?>
What am I doing wrong?
There are two ways to make links:
CodeIgniter helper style:
<?php echo anchor('about', 'About us', 'title="About us link"'); ?>
More common HTML with URL echo:
About us
Both will output:
About us
Though if I understand what you are trying to achieve, your mistake is elsewhere.
You don't include the views part, as your URL should point to the controller, not a view. The only case is if you have a controller named views.
CodeIgniter is set up so that it doesn't include file extensions like .html in URL's by default. It does if you've set them up in your config file in $config['url_suffix'] = '';, which is null by default.
See if you've made any of these mistakes.
That is another way on how you do the URL if you are using the URL helper in CI. You should try this, make the base_url() as the value for href. Try this,
About Us
You have to try like this
About Us
or you can give like
About Us
and in the "about" function you put
$this->load->view('about');
but i think the firstone will works for you fine.

How do I separate the files for 'widgets' in codeigniter?

I have a basic cms that loads content into pages that have mustache tags to indicate where in the html code those contents will appear.
The contents are specified in a widget model which indicate which type of content is to be displayed, so for example, freetext with id. or another model and id. each one of those models will be displayed differently based on the model they are based on.
I can imagine this becoming and bit unwieldy, is there a way to have a separate folder to put those widgets in so that it doesn't clutter my main code.
Something like apotomo does on rails would be good, but for codeigniter.
A widget model? That is not so nice. Have you tried looking at PyroCMS?
https://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/modules/widgets/libraries/Widgets.php
From the sound of it you may be more interested in our Plugins library (sounds like the same thing with a different name). It is set up with a MY_Parser and runs on top of Dan Horrigan's Simpletags implementation.
Either way this has all be done plenty. If you want some more specific tailored advice you might have to demo some of your code.
Create a folder inside application/views called widgets. Put your widgets inside that folder and create a separate file for each widget (d0h).
Next, you have 2 options (at least that i know of):
a.) Load the widgets into variables inside the controller, then pass them to the main/general view
$data['widget_twitter_feed'] = $this->load->view('widgets/twitter', '', false);
$data['widget_something'] = $this->load->view('widgets/something', '', false);
$this->load->view('my_main_view', $data);
b.) Load the widgets inside the main/general view itself
<html>
...
<div id="sidebar">
<?php $this->load->view('widgets/twitter'); ?>
</div>
...
<div id="footer">
<?php $this->load->view('widgets/something'); ?>
</div>
...
</html>

Resources