views:

41

answers:

1

I've built one variable (horaires_lundi) in this file :

app/code/community/Unirgy/StoreLocator/controllers/Adminhtml/Locationcontroller.php

->setTitle($this->getRequest()->getParam('title'))
->setNotes($this->getRequest()->getParam('notes'))
->setStreetAddress($this->getRequest()->getParam('street_address'))
->setHorairesLundi($this->getRequest()->getParam('horaires_lundi'))

All variables are well displayed in JavaScript in this file :

app/design/frontend/default/default/template/unirgy/storelocator/map.phtml

(function(){
    var storeLocator = new UnirgyStoreLocator({
        mapEl: $('map'),
        sidebarEl: $('sidebar'),
        searchUrl: '<?php echo $this->getUrl('ustorelocator/location/search')?>',
        generateSidebarHtml: function(m) {
            return '<span style="font-size:14px; color:#C68804;"><b>' + m.title + '</b></span><br/>(Distance : ' + parseFloat(m.distance).toFixed(1) + ' ' + m.units + ')<br/>'
                + m.street_address + '&nbsp;' + m.test + '&nbsp;' + m.city + '<br/><b>' + m.notes + '</b><br/>';
        },
        generateMarkerHtml: function(m) {
            var url = m.website_url.replace(/\s/,'');
            var dataForm = new VarienForm('form-validate', true);
            return '<span style="font-size:14px; color:#C68804;">' + m.title + '</span><br/>'
                + '<?php if (trim($this->getHorairesLundi())!=""): ?>Lun&nbsp;'+ m.horaires_lundi +'<?php else : ?>No horaire lundi<br/><?php endif; ?>'

variable m.horaires_lundi in JavaScript is well displayed in frontend. But I can't make a condition in PHP to display m.horaires_lundi only if m.horaires_lundi exists...

Above I made a try with

<?php if (trim($this->getHorairesLundi())!=""): ?>

Is it a goog method? what else must I do? Is there an other method with something like:

<?php if (Mage::helper(...

I've found a tutorial about Magento but can't find my solution.

+1  A: 

There's a significant distinction between PHP and JavaScript: the former is a server-side scripting language, the latter a client-side scripting language. Though you can use PHP to conditionally echo JavaScript code to the browser (which I don't recommend), you can't access JavaScript variables in PHP. Just test for the presence of a JavaScript variable in the script itself.

If I understand your goal correctly, you can rewrite your last line of code to

return '<span style="font-size:14px; color:#C68804;">' + m.title + '</span><br/>' +
    ((m.horaires_lundi) ? 'Lun&nbsp;' + m.horaires_lundi : 'No horaire lundi') + '<br/>';
Marcel Korpel
Thanks a lot, you make my day !Thanks too for "indent your code with 4 spaces"
Bargalunan