4

I'm pretty new to this, but I have been stumbling on a feature I would like to have. I'm using Drupal 7.

I've created a some blocks on my front page. In one of those blocks I have a some div's and text that goes inside of my block. That works just fine and looks great.

Problem is that I want to place some randomly generated testimonials inside this block and I can't figure out how to do so.

Now, I've already created another view block that lists my testimonials randomly, but I just need to know the correct php code. Note: I've also enabled the PHP filter module, but it doesn't seem to be working.

I can easily assign my random testimonial view to a block, but I want to combine some HTML along with the testimonial and I just dont know enough about php.

Example:

Some random text here...

**PHP to bring in my random block of testimonials from views**

Some random text here...

I've also heard that placing in PHP like this is not good practice. If anyone has a better way for me to do this I would appreciate it. Like I mentioned, placing this view in a empty block works fine. I just want to be together with some html.

Thanks!

-Dan

2

You can achieve it by following snippet in your block,

  Some random text here...
  echo views_embed_view('view-name', $display_id = 'display-name');
  Some random text here...

eg:

 <?php echo views_embed_view('test', $display_id = 'block'); ?> //dont forgot to enable text format as PHP.
  • Brilliant! That's exactly what I needed and it works perfectly. Thanks Anoop!! – Dan Oct 12 '12 at 15:18
  • I can't get this to work. I'm using the following code (the first variable being the name of the view and the second being that view's block display name) – Sam Apr 25 '15 at 15:11
  • I'm using the following code and its not working. 'home-page'totals' is the name of the block and 'ipe-resources' is the disp <?php echo views_embed_view('home-page-totals', $display_id = 'ipe-resources'); ?> – Sam Apr 25 '15 at 15:13
0

you can use Insert block (it's div version but it work perfectly)module to insert a block into another block.
See the Readme file

  • Thanks for the suggestion abd. I'd love to do this without another module. Is what I want to do that strange? I went ahead and moved my html back into the template with my php string of " <?php print render($page['twocolumn']); ?>" and now its working fine. But I guess sometime down the road I will learn why its not good to put html content inside a template file. – Dan Oct 12 '12 at 4:03
  • don't worry #dan :D – abd Oct 12 '12 at 10:30
0

Late answer for anyone who comes across this.

The cfrblock module, based on renderkit, allows to combine blocks and elements in any way you want, also supports conditional logic.

Follow the instructions on the module page:

  • Install cfrblock, renderkit, cfrpreset. This involves some composer packages, you will find instructions on renderkit module page.
  • Go to admin/structure/cfrpreset, add a preset for "BlockInterface".
  • Configure the block as you like.
  • Go to admin/structure/block. The presets you just created will appear there as blocks.

Possibilities when configuring the block:

  • Sequence of elements (blocks or other things).
  • Views display.
  • Views exposed form.
  • Existing block.
  • Element wrapped into a special container.
  • Combination of the above, with endless nesting.

If you are crafty and creative, you can create your own elements and then recombine them into a block.

I am using this on a website where I have more custom plugins than you currently find in renderkit. I should add some of those to the contrib module..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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