How to get tinybutstrong mergeblock with condition working for empty value - tinybutstrong

I am using tinybutstrong as a templating engine.
I am trying to get the active link to display in a different color.
The following is my (trimmed down) PHP side:
$links = array (
'' => 'Home',
'about' => 'About Us',
'faq' => 'FAQ',
'contact' => 'Contact Us',
);
$uri = substr($_SERVER['REQUEST_URI'], 1);
$TBS->MergeBlock('blkLinks', 'array', $links);
Html Template:
<ul>
<li>[blkLinks.val;]</li>
</ul>
While it generates the html fine and nicely changes the color of the links when that page is currently active, this does not work for the empty (/) link.
How can I fix that?

Simply replace the condition
[onload.uri]=[blkLinks.$]
with
'[onload.uri]'='[blkLinks.$]'
The point is that when [onload.uri] is an emprty string, then the expression can be ambiguous. Using the string delimitors, the expression is clear for TBS.

Related

x-editable drop down from remote not working

I am using X-editable bootstrap version 2
I am using codeigniter . But the text area and text box is working fine for me but drop down is not working .
in my view
< a href="#" id="contract" data-type="select" data-pk="1" data-source="<?php echo base_url('property/contract_get_update')?>" data-title="Select Contract type" class="" >contract data </a>
$( document ).ready(function() {
$('#contract').editable();
});
in my controller
public function contract_get_update()
{
echo "{'M': 'male', 'F': 'female'}";
}
i just tested with this output not working i tried many tricks but it is not seems to be working.
i want to display details from table name contract how can i get that value as a drop down in x-editable
I answered you on gitHub too. The problem is with your json format.
Try this:
$contract_types = array();
$contract_types[] = array('value' => 'M', 'text' => 'male');
$contract_types[] = array('value' => 'F', 'text' => 'female');
echo json_encode($contract_types);
If you are looping through a db query of results try this in your function:
foreach($results AS $result){
$json_response[] = array('value' => $result['id_column'], 'text' => $result['your_column']);
}
echo json_encode($json_response);
You need to use a custom class with text and value members (case sensitive) to enumerate it as a List of type this class then use it to response after ajax call.

Laravel Blade Form, is it possible to create a textbox input if a user selects the 'other' option?

This may not be possible with blade, but I was wondering how to generate a textbox input from an 'other' option in a select dropdown. Is this possible?
{{ Form::select('showType', array(
'Theater' => 'Theater',
'Club' => 'Club',
'Festival' => 'Festival',
'Arena' => 'Arena',
'Closed Show' => 'Closed Show',
'College Show' => 'College Show'
'Other' => 'some kind of text input appears instead'
)}}
You'll need to use javascript to do that, Blade can't help much. But you can create, in Blade, your form input and set a hidden class to it and, when your user select the 'other' option you just have to remove that class.
You need to use JavaScript to do this because it happens on the client side. PHP and Laravel and Blade all happens on the server. An simple jQuery example:
$('select').on('change', function(){
$('body').append("<input type='text' value='whatever'/>");
});

Why wysiwyg plugin in magento gets me broken links?

When I try to insert an image to the wysiwyg editor in Magento it places the right variable of the image path in the media directory.
But, wysigyg doesn't find the right path/url, example:
I inserted:
<p><img src="{{media url="wysiwyg/blog/Screen_Shot_2013.png"}}" alt="" /></p>
But, in the preview it gets me the next broken src:
<img src="https://localhost/index.php/admin/cms_wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ii93eXNpd3lnL2Jsb2cvU2NyZWVuX1Nob3RfMjAxMy5wbmcifX0,/key/1a966015551bf00867319d23c9914b48/" alt="" data-mce-src="https://localhost/index.php/admin/cms_wysiwyg/directive/___directive/e3ttZWRpYSB1cmw9Ii93eXNpd3lnL2Jsb2cvU2NyZWVuX1Nob3RfMjAxMy5wbmcifX0,/key/1a966015551bf00867319d23c9914b48/">
And of course, it doesn't show the image. Also this happens with links and other media files.
System -> Configuration -> General -> Content Management -> Use Static URLs for Media Content in WYSIWYG for Catalog to Yes
The option wich Le Nguyen gave is not really a good solution.
Like hsanders said:
There are some pretty big drawbacks to doing this: The static URL will be a non-secure URL and If you change your base URL the URLs on the images will not update to reflect that are the two I can think of immediately.
A possible solution to "fix" the problem (not the right way in my opinion, but at least better than the static Url option) would be to add some code to the following file:
vendor/magento/module-catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php
Add on line 747:
'add_variables' => false,
'add_widgets' => false,
'add_directives' => true,
Also change
lib/web/mage/adminhtml/wysiwyg/tiny_mce/setup.js and add the following on line 384 (below content = editor.getContent();:
content = this.decodeContent(content);
Now you need to execute the following command to complete the process:
php bin/magento cache:flush
Hope this helps.
(Keep in mind you've just edited core files)
in your Form.php you configuration should be like below
protected function _prepareForm()
{
$model = Mage::registry('testimonial_data');
$form = new Varien_Data_Form();
$this->setForm($form);
$form->setHtmlIdPrefix('testimonial_');
$wysiwygConfig = Mage::getSingleton('cms/wysiwyg_config')->getConfig(array('add_variables' => false, 'add_widgets' => false,'files_browser_window_url'=>$this->getBaseUrl().'admin/cms_wysiwyg_images/index/'));
$fieldset->addField('content', 'editor', array(
'name' => 'content',
'label' => Mage::helper('testimonials')->__('Content'),
'title' => Mage::helper('testimonials')->__('Content'),
'style' => 'width:700px; height:500px;',
'state' => 'html',
'config' => $wysiwygConfig,
'required' => true,
));
}
hope it will work for you.

Zend forms: How to surround an image-element with a hyperlink?

How do I surround an image element inside a Zend form with an HTML <a href>-Tag? I specifically don't want a JS onClick()-Event as it seems not to work properly in my case (see question Zend: Redirect from form without validation).
This is how I add the image element inside the form, right now the hyperlink is displayed as Text "Link" right next to the image:
$this->addElement('image', 'btnBack', array (
'name' => 'btnBack',
'id' => 'btnBack',
'label' => '',
'title' => 'Go back',
'alt' => 'Go back',
'src' => '/img/undo.png'
));
$this->getElement('btnBack')
->setDescription('Link')
->setDecorators(array(
'ViewHelper',
array('Description', array('escape' => false, 'tag' => false)),
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
'Errors',
));
This sounds like a bad idea. From the look of your other question, all you want is an image 'button' that goes to a specific URL. You shouldn't try and do this with an image input, since this is a type of submit button, and so clicking it will submit the form. If you're trying to override this with javascript or wrap the whole thing with a HTML link you're trying to solve the wrong problem.
The easiest approach is probably to use a button input. You can then style it with CSS to make it look like an image, and add your javascript onclick action to make it do what you want. Since input type="button" elements don't do anything onclick by default, you shouldn't have any of the problems you had before.
$this->addElement('button', 'btnBack', array(
'id' => 'btnBack',
'label' => 'Go back',
'onclick' => "window.location='/admin/groupoverview'"
));
then in your stylesheet (replace the width and height with the correct image dimensions):
#btnBack {
background-image: url(/img/undo.png);
width: 123px;
height: 123px;
border: 0;
text-indent: -1000px;
cursor: pointer;
}
the text-indent shifts the text label out of view. If you absolutely don't want these rules in your stylesheet you could put them inline on the form element by passing a style attribute instead.

Cakephp 1.3, Weird behavior on firefox when using $this->Html->link

Greetings,
I am getting a very weird and unpredictable result in firefox when using the following syntax:
$this->Html->link($this->Html->div('p-cpt',$project['Project']['name']) . $this->Html->div('p-img',$this->Html->image('/img/projects/'.$project['Project']['slug'].'/project.thumb.jpg', array('alt'=>$project['Project']['name'],'width'=>100,'height'=>380))),array('controller' => 'projects', 'action' => 'view', $project['Project']['slug']),array('title' => $project['Project']['name'], 'escape' => false),false);
OK I know it is big but bear with me.
The point is to get the following output:
<a href="x" title="x">
<div class="p-ctp">Name</div>
<div class="p-img"><img src="z width="y" height="a" alt="d" /></div>
</a>
I'm not sure if this validates correctly both on cakephp and html but it works everywhere else apart from firefox.
You can actually see the result here: http://www.gnomonconstructions.com/projects/browser
To reproduce the result use the form with different categories and press search. At some point it will happen!!
Although most of the time it renders the way it should, sometimes it produces an invalid output like that:
<div class="p-cpt">
name
</div>
<div class="p-img">
<img src="x" width="x" height="x" alt="x" />
</div>
Looks like it repeats the link inside each element.
To be honest the only reason I used this syntax was because cakephp encourages it.
Any help will be much appreciated :)
I am guessing that the name of some projects is null. According to the documentation, if you pass null as the second argument to the div() method, it will not generate the closing tag (and the resulting markup will be invalid).
The example of invalid markup that you pasted above appear to have come from Firebug rather than Page Source. Use Page Source to view the actual markup sent to the browser. The anchor tag is not repeated.
I rewrote your code to better see what happens. Copy it into one of your views, change 'My Project' to null, and notice how it will affect the $name_div variable:
<div class="p-cpt">My Project</div> will turn into <div class="p-cpt">.
<?php
$project['Project']['name'] = 'My Project';
$project['Project']['slug'] = 'my-project';
$image = $this->Html->image(
'/img/projects/' . $project['Project']['slug'] . '/project.thumb.jpg',
array(
'alt' => $project['Project']['name'],
'width' => 100,
'height' => 380
)
);
$name_div = $this->Html->div('p-cpt', $project['Project']['name']);
$image_div = $this->Html->div('p-img', $image);
$link = $this->Html->link(
$name_div . $image_div,
array(
'controller' => 'projects',
'action' => 'view',
$project['Project']['slug']
),
array(
'title' => $project['Project']['name'],
'escape' => false
)
);
var_dump($image);
echo 'Notice what happens below if project name is null.';
var_dump($name_div);
var_dump($image_div);
var_dump($link);
echo $link;

Resources