0

I have a text field that I get with <?php print render ($content['field'][0]['#markup']); ?> in node.tpl. I'd like to somehow make loading the markup require a click, and deselecting it to put the placeholder markup back. It's a select dropdown if it matters.

I thought javascript might work, to test if scripts worked in node.tpl I tried

var test ="<?php print render ($content['field'][0]['#markup']);?>"; 
document.write(test);

but it loaded the markup for every node on the page in one line. My php/js skills are weak so I'm hoping there's a module that might help me. I'm open to any suggestions though.

1 Answer 1

0

You can try to do something like this:

<div class="hidden-text">
<span class="text-change">Your Placeholder</span>
</div>

<script>
jQuery.noConflict();
(function ($) {
$(function(){
$(".hidden-text").click(function () {
    ($(".text-change").text() === "Your Placeholder") ? $(".text-change").text("<?php print render ($content['field'][0]['#markup']);?>") : $(".text-change").text("Your Placeholder");
});
});
})(jQuery);
</script>
3
  • I think something like this may work. It didn't with this field, it's a full html text field with a <select> in it though. Does .text support that?
    – James
    Commented May 27, 2015 at 23:13
  • forgot to write @
    – James
    Commented May 27, 2015 at 23:19
  • No, text() doesn't render HTML tags, it will show HTML tags as text, so in that case change every .text with .html...there is an example so you can see the difference between text() and html(): jsfiddle.net/hossain/sUTVg
    – mixerowsky
    Commented May 28, 2015 at 17:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.