TYPO3 get category uid at FLUID template (sys_category) - templates

I try to show my category uid or name as a class="category.uid" at my FLUID template.
If I try <f:debug>{data}</f:debug> I'll see there are an output like: categories => '1' (1 chars)
But how can I write the category-uid or -name into my FLUID/HTML, similar like this:
<div id="container" class="{data.nav_title}">
<!-- I need the categories -->
<div id="container" class="{categories.uid}">
THanks for your help.
EDIT: some screenshots
The info is in table sys_categorytitle, uid, pid ..
`{data}

The same problem is discussed here (see 11:30 - 12:31).
So there is no viewhelper for this. You have to register a ContentController with Flux.

I have used a variant of the solution here: How can I get the category object in Fluid of Typo3 Content Element Pictures?
TypoScript
lib.categories = CONTENT
lib.categories {
table = sys_category
select {
pidInList = root
selectFields = sys_category.uid
join = sys_category_record_mm on sys_category_record_mm.uid_local = sys_category.uid
where.field = recordUid
where.wrap = sys_category_record_mm.uid_foreign=|
}
renderObj = COA
renderObj {
1 = TEXT
1 {
field = uid
stdWrap.noTrimWrap = | cat-||
}
}
}
Fluid Template
<f:cObject typoscriptObjectPath="lib.categories" data="{recordUid: data.uid}" />

Sorry for the answer - i do not have enough reputation to comment.
What is {data}?
Is it something you get from your controller like?
$data = $this->configurationManager->getContentObject()->data;
$this->view->assign('data', $data);
If so, then you will need to do some extra processing in your controller since $data is an associated array and not an object / model with injection of relations.

Related

Virtuemart: get PDF invoice link on order_done step

I have Joomla 2.5.17 an Virtuemart 2.0.26d. I want the PDF invoice download link on the order_done step which is rendered by order_done.php view.
I already configured the virtuemart so the order status is on "CONFIRMED" - "C" meaning as the order is paced, the PDF invoice had been already generated.
Ok, i got it. So this is what you have to do if you want the download link in order_done step. Assuming your PDFs are stored in "media/vmfiles/invoices/" you need to add some code to components/com_virtuemart/controllers/cart.php line about 477 where "else if($task=='confirm')" block starts:
...
$cart->confirmDone();
$view = $this->getView('cart', 'html');
$securePath = VmConfig::get('forSale_path',0);
$segments = explode('/', $securePath);
$folderOnServer = $segments[sizeof($segments)-3].'/'.$segments[sizeof($segments)-2];
$orderModel = VmModel::getModel('orders');
$invoiceId = $orderModel->getInvoiceNumber($cart->virtuemart_order_id);
$pdfName = "{$folderOnServer}/invoices/vminvoice_{$invoiceId}.pdf";
$view->setLayout('order_done');
$view->pdfName = $pdfName;
$view->display();
...
also a bit code in view templates/{yourtheme}/html/com_virtuemart/cart/order_done.php:
<div class="get-pdf"><?php echo JText::_('get_your_pdf'); ?> <?php echo JText::_('DOWNLOAD_PDF') ?> <br/></div>

angularjs ui-router: find level of current state

So I'm using ui-router and stateparams to nest child states, and it works well. I'm now trying to find a way to dictate a css class what state level the app is at. main.route1.section1 would be 3 levels.
Here's some non-working code to help show:
<div ng-class="{findState().currentCount}"></div>
app.run(function($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
$rootScope.findState = function() {
var currentName = $state.current.name;
var currentMatch = currentName.match(/./g);
$rootScope.currentCount = currentMatch.length;
};
});
I'm basically looking for a way to take $state.current.name which say equals main.route1.section1 and split it at the dot and count how many are in the array and return that number to the mg-class. Unless you have a better idea... like a regex filter?
Take a look of the object $state.$current (instead of $state.current). In particular, the property path : it's an array representing the state hierarchy of the current state.
So what you are looking for is : $state.$current.path.length

Google Custom Search with XSLT

I'm trying to implement the google custom search engine to a website running with xslt.
This code is located in the head section
(function() {
var cx = '..............';
var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s);
})();
And this snippet in the body
<gcse:search></gcse:search>
But i only get following error Warning: DOMDocument::load(): Namespace prefix google on search is not defined
Some idea why? Do i need a special xmlns?
Cheers
I am trying to make sense of https://developers.google.com/custom-search/docs/element#overview and your posted question. I am kind of guessing but based on https://developers.google.com/custom-search/docs/element#html5 try to replace <gcse:search></gcse:search> in your code with <div class="gcse-search"></div>, that way I hope your XSLT input is namespace well-formed and your attempt to include the Google search in the transformation result works.
Just bringing out how to add attributes example from the links shared by Martin above:
HTML5-valid div tags
You can use HTML5-valid div tags as long as you observe these guidelines:
The class attribute must be set to gcse-XXX
Any attributes must be prefixed with data-.
For example:
<div class="gcse-searchbox" data-resultsUrl="http://www.example.com"
data-newWindow="true" data-queryParameterName="search" >

Adding a search box to filter a list of results in Symfony?

I need to put a search box within a list of objects as a result of a typical indexSuccess action in Symfony. The goal is simple: filter the list according to a criteria.
I've been reading the Zend Lucene approach in Jobeet tutorial, but it seems like using a sledge-hammer to crack a nut (at least for my requirements).
I'm more interested in the auto-generated admin filter forms but I don't know how to implement it in a frontend.
I could simply pass the search box content to the action and build a custom query, but is there any better way to do this?
EDIT
I forgot to mention that I would like to have a single generic input field instead of an input field for each model attribute.
Thanks!
I'm using this solution, instead of integrating Zend Lucene I manage to use the autogenerated Symonfy's filters. This is the way i'm doing it:
//module/actions.class.php
public function executeIndex(sfWebRequest $request)
{
//set the form filter
$this->searchForm = new EmployeeFormFilter();
//bind it empty to fetch all data
$this->searchForm->bind(array());
//fetch all
$this->employees = $this->searchForm->getQuery()->execute();
...
}
I made a search action which does the search
public function executeSearch(sfWebRequest $request)
{
//create filter
$this->searchForm = new EmployeeFormFilter();
//bind parameter
$fields = $request->getParameter($this->searchForm->getName());
//bind
$this->searchForm->bind($fields);
//set paginator
$this->employees = $this->searchForm->getQuery()->execute();
...
//template
$this->setTemplate("index");
}
It's important that the search form goes to mymodule/search action.
Actually, i'm also using the sfDoctrinePager for paginate setting directly the query that the form generate to get results properly paginated.
If you want to add more fields to the search form check this :)
I finally made a custom form using the default MyModuleForm generated by Symfony
public function executeIndex {
...
// Add a form to filter results
$this->form = new MyModuleForm();
}
but displaying only a custom field:
<div id="search_box">
<input type="text" name="criteria" id="search_box_criteria" value="Search..." />
<?php echo link_to('Search', '#my_module_search?criteria=') ?>
</div>
Then I created a route named #my_module_search linked to the index action:
my_module_search:
url: my_module/search/:criteria
param: { module: my_module, action: index }
requirements: { criteria: .* } # Terms are optional, show all by default
With Javascript (jQuery in this case) I append the text entered to the criteria parameter in the href attribute of the link:
$('#search_box a').click(function(){
$(this).attr('href', $(this).attr('href') + $(this).prev().val());
});
And finally, back to the executeIndex action, I detect if text was entered and add custom filters to the DoctrineQuery object:
public function executeIndex {
...
// Deal with search criteria
if ( $text = $request->getParameter('criteria') ) {
$query = $this->pager->getQuery()
->where("MyTable.name LIKE ?", "%$text%")
->orWhere("MyTable.remarks LIKE ?", "%$text%")
...;
}
$this->pager->setQuery($query);
...
// Add a form to filter results
$this->form = new MyModuleForm();
}
Actually, the code is more complex, because I wrote some partials and some methods in parent classes to reuse code. But this is the best I can came up with.

How to make parameter optional in Zend Framework Router

I would like to know the .ini config file setup to make a route wherein the page number parameter is optional so that
http://news.mysite.com/national
http://news.mysite.com/national/1
point to the same page.
I have the code as follows
resources.router.routes.news_list.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_list.route = "([a-zA-Z0-9\-]+)/([0-9\-]+)"
resources.router.routes.news_list.defaults.module = "news"
resources.router.routes.news_list.defaults.controller = "index"
resources.router.routes.news_list.defaults.action = "category"
resources.router.routes.news_list.defaults.page = 1
resources.router.routes.news_list.map.1 = "categ"
resources.router.routes.news_list.map.2 = "page"
resources.router.routes.news_list.reverse = "%s/%s"
can some1 help me out with a solution to modify this code to make it work for both urls
You can do this without the regex route using:
routes.news_list.route = ":action/:page"
routes.news_list.defaults.module = "news"
routes.news_list.defaults.controller = "index"
routes.news_list.defaults.action = "category"
routes.news_list.defaults.page = 1
I assume that you want every request to go to the "news" module and the "index" controller. Only the action and the page are variable in the url.
resources.router.routes.news_list.type = "Zend_Controller_Router_Route_Regex"
resources.router.routes.news_list.route = "([a-zA-Z0-9-]+)/?([0-9]+)?"
resources.router.routes.news_list.defaults.module = "news"
resources.router.routes.news_list.defaults.controller = "index"
resources.router.routes.news_list.defaults.action = "category"
resources.router.routes.news_list.defaults.page = 1
resources.router.routes.news_list.map.1 = "categ"
resources.router.routes.news_list.map.2 = "page"
resources.router.routes.news_list.reverse = "%s/%d"
Something like this could work too in case you need to use Regex.