How to extend page module in contao? - contao

I want to insert image in page module. Anybody have idea how to extend page in contao ?
See screen for more clarification.
http://screencast.com/t/JXk5thjlvHv
See attached screen .. my idea is like this.

You could do that by giving the pages specific CSS classes in their settings. This CSS class will also be used in the regular navigation modules. This way you can define the page's icon in your own stylesheets.

That actually depends how much you want to do.. the easy way: define classes... But thats not the most flexible one.
Lets say you have a custom icon font. Or maybe just FontAwesome. And you want to use these Icons to be shown. In this case, I would install the IconPicker Module by Rocksolid and write a custom module:
/system/modules/z-customs/dca/tl_page.php
$GLOBALS['TL_LANG']['tl_page']['icon']=array('Pageicon', 'Set an Icon for the Page');
$GLOBALS['TL_DCA']['tl_page']['fields']['icon'] = array(
'label' => &$GLOBALS['TL_LANG']['tl_page']['icon'],
'exclude' => true,
'inputType' => 'rocksolid_icon_picker',
'eval' => array(
'fieldType'=>'radio',
'tl_class'=>'w100 clr',
'iconFont' => 'files/fonts/fontawesome-webfont.svg',
),
'sql' => "varchar(100) NOT NULL default ''",
);
/templates/nav_default.html5
<?php if($item['icon']): ?>data-icon="&#x<?= $item['icon']; ?>"<?php endif; ?>
This part can be added to the <li> or the <strong> or a. You may also add a class to the element, to make sure only the elements that have an Icon get the appropriate style.
To get the Icon into the CSS you would just do something like this:
a:before {
content: attr(data-icon);
font-family: "FontAwesome";
}

Related

Typo3 Fluid detect Links in Text

This Code is showing a Textarea Input from the Backend in my Frontend:
<f:format.nl2br>{data.textfield}</f:format.nl2br>
Its possible there are Links in it as simple text for example:
http://www.example.com
Is it possible somehow to detect those links and wrap a linktag around it with Typo3 6 and Fluid?
Its rather easy in Javascript but if possible I prefer a Typo3/Fluid solution here.
why dont you use the RTE for your Textfield in the Backend and render it in Fluid with
<f:format.html>{data.textfield}</f:format.html>
If you do it like this, you have your line breaks rendered and all the Links, too. You enable the RTE features in your TCA-Configuration:
'textarea' => array(
'exclude' => 0,
'label' => 'your_label_from_locallang.xlf',
'config' => array(
'type' => 'text',
'cols' => 40,
'rows' => 15
),
'defaultExtras' => 'richtext[]'
),
Is the fluid used in context of an extension? If so make the check on php side and bind a boolean value to the view. You can then use something like this:
<f:if condition="isLink">
<f:then>
<f:link.external uri="{data.textfield}" target="_blank">{data.textfield}</f:link.external>
</f:then>
<f:else>
<f:format.nl2br>{data.textfield}</f:format.nl2br>
</f:else>
</f:if>
Unfortunately condition is very limited in what it can check on fluid side only so this won't help if you can't use php.
Another possibility would be to create a ViewHelper for that.

How to control page get parameter in Yii CListView?

Using Yii 1.1.12. I have a CListView with ajax turned off:
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'ajaxUpdate' => false,
)); ?>
The url for the link to the second page looks like:
http://www.example.com/products?Product_page=2
I want the url to look like:
http://www.example.com/products?page=2
How can I achieve this?
(A bonus would be to also describe how to get a url like http://www.example.com/products/page/2)
Update
As pointed out by elbek, I see the CListView has a pager property of type CLinkPager. This in turn has a pages property of type CPagination which has a property pageVar which is described as:
name of the GET variable storing the current page index. Defaults to
'page'.
Sounds like it could be what I'm looking for, not sure how to modify this from the CListView though.
Additionally to change the pageVar you have to modify the $dataProvider. You can do this when you are defining it in the controller action:
$dataProvider=new CActiveDataProvider('Products',array(
'pagination'=>array(
'pageVar'=>'page'
)
));
Alternatively you can of course modify the $dataProvider in the view itself before using it in the CListView : (not recommended-owing to separation of concerns)
$dataProvider->pagination=array('pageVar'=>'page');
$this->widget('zii.widgets.CListView', array(/*rest of your code*/));
But with this change, to make your url look like http://www.example.com/products/page/2 you'll need to slightly change the rule in urlManager from Suvera's answer:
'products/page/<page:\d+>'=>'products/index',
Note: If you don't need that type of url, you don't need the above rule, just specifying the pageVar does it.
enable the urlManager component on your config. And add the following rule at the top.
'urlManager'=>array(
......
'rules'=>array(
'products/page/<Product_page:\d+>'=>'products/index', //Add it in top
...........
...........
),
),
the above rule will create a url something like http://www.example.com/products/page/2
The value part in the rule products/index is products controller and index action (this is important, so point it out to your actual route).
you can even create urls whatever way you want.
ex 1:
'products/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/products/2
ex 2
'TheAvengers/vs/Loki/<Product_page:\d+>'=>'products/index'
will give you http://www.example.com/TheAvengers/vs/Loki/2
I think CListView has pager attribute(from its parent class)
You can try to set some attributes for this. I think it is CLinkPager instance.

customize td inner html in mvccontrib grid

I wonder if there way to customize td inner HTML of grid, for example I need to bound some field, and make clickable.
Didn't found any other way, except adding onclick attribute.
Columns(column => column.For(x => x.GotToPursue).Attributes(#onclick => "align-right")
Any suggestions?
The only way to this I've found is to write your on extension method, working with already formed innerhtml to change it.

embedded form relations with doctrine

I currently using ahDoctrineEasyEmbeddedRelationsPlugin to embed a Block form into a Page form.
All works well, but I'd like to hide the label of the embeddedRelation.
I've created a 'homepage-main-top' Block within the Page form in the admin, now when editting this Page, I now see 'homepage-main-top' is randomly appearing before the embedded block relation
Looking at the plugin docs, there doesn't seem to be anything relating to removing/hiding this:
http://imageshack.us/photo/my-images/197/relation.png
Does anyone know how to not display this?
Thanks
I've been struggeling with somewhat the same problem, only I needed to style the label instead of hidding / stripping it.
From what I've found out there is no simple way to manipulate the label of the embedded form, but I figured the following 'hack'.
The embedRelation method accepts a inner- and outer-decorator parameter. You can use these to wrap extra markup around the label and the embedded form. You can then use CSS to hide the label using a specific id / css class.
By openning tags in the outerdecorator and closing them in the inner decorator you can wrap the label in a tag (which is rendered inbetween the two). It is kind of tricky to make sure your HTML is still valid.
I know this is kind of a crappy solution but I haven't found a better way up until now.
Add this line to your parent form:
$this->widgetSchema['EmbeddedFormName']->setLabel(' ');
If the above doesn't work, try using the 'newFormLabel' option (from the plugin's documentation).
$this->embedRelations(array(
'RelationName' => array(
// ...
'newFormLabel' => ' ',
// ...
),
// ...
));

Dynamic page titles in Symfony 1.4

I'm wondering if anyone's got any good advice/experience regarding setting dynamic meta titles in Symfony?
Currently, the solution I'm aware of would be to use the following code to set a title individidually in each action:
$this->getResponse()->setTitle('This is a title');
Because I also need translated titles, I could call the i18n helper in the action to get them included in the extracted XLIFFs. No special SEO stuff needed, just a clean title.
However, the above does require that I tweak every single action separately. View.yml is not suitable as I frequently have multiple actions/templates per module.
Is anyone aware of a better approach in Symfony or is this indeed the right/only way to go?
Thank you.
You should use slots.
In your layout <head> tag:
<title><?php echo get_slot('page_title', __('Default page title here')) ?></title>
And in an action template:
<?php slot('page_title', __('Action page title goes here')) ?>
I think writing separate titles in every action is OK. But if you want to add some global prefix you can use something like this in layout:
<title>SITE NAME — <?= $sf_response->getTitle() ?></title>
Also you can probably manipulate a title per module using preExecute() method in actions.
I personally like using the yml files, it separates 'configuration' from code
To deal with dynamic titles I do the follow:
in apps/frontend/config/app.yml
all:
title_separator: ' - '
title_default: 'TITLE'
in apps/frontend/config/view.yml
default:
metas:
title: %APP_TITLE_DEFAULT%
If you need to have data from your actions put into the title, create file lib/myActions.class.php with the following content:
<?php
class myActions extends sfActions
{
protected function setTitle($string)
{
$this->getResponse()->setTitle($string . sfConfig::get('app_title_separator') . sfConfig::get('app_title_default'));
}
}
?>
(note: modify this as you like, e.g. put default title at front)
Then change your action.class.php to extend myActions instead of sfActions
class memberActions extends myActions
and whenever you need to change the title, just call this in your action
$this->setTitle('This is how I roll');
and you will get the following title (if using the same config as I did above):
This is how I roll - TITLE
$i18n = $this->getContext()->getI18N();
$this->getResponse()->setTitle('Your title' . ' | ' . $i18n->__('your module name'));

Resources