Jump to content

Having trouble with Blocks


dschreiber

Recommended Posts

Posted

Hello!

I'm having some trouble getting a block to work in a template.  This is my first attempt, so it's probably something wrong that I'm doing.  

Here's my template where the block should go:

Selection_902.thumb.png.7e450c8b9877aa9eb91a9837d52bf502.png

Here's the block Details:

Selection_900.thumb.png.72a1fd3b5675aa5b85e66a3f99d23e0b.png

And finally, here's the block content:

Selection_901.thumb.png.ab8327fb86e572dc48582ae0ececbc9d.png

The block I created is a Custom Block / Manual HTML.  The block content was originally a chunk of the template content.  I was experimenting to see if I could move it into a block with it still able to work.  Nope.  Instead, the block content simply isn't displayed.  Any suggestions?

Thanks!

Posted
11 minutes ago, dschreiber said:

I was experimenting to see if I could move it into a block with it still able to work.  Nope. 

“Nope” is correct. These type of blocks are processed independently. They won’t have access to the $database variable just because the blocks are called within the template. 

Posted

Thanks for the reply.  I totally appreciate it.  I have a follow-up question:  Is it possible to fetch the current database in a block?  For example, I tried adjusting my block like this...

{{$database = \IPS\cms\Databases::load($database->id);}}

<div class="cDevHeader" id="elDevDocs_header" style="background-image:url('/forums/uploads/set_resources_3/6554b6be8c0d829a8bf63ae0c82cf121_codebackground.jpg');">
  <h1 class="ipsType_pageTitle">
      {$database->_title}
	  <div class='ipsType_normal'>
	    {$database->_description}
	  </div>
  </h1>
</div>

.. but got blank output.  (Is there some log file I can view that shows me why a block might not display?)

Thanks again!

Posted

Oh, good point.  Is there a way to make my block code aware of the current database?  If you see what I'm trying to achieve, can you point me toward a solution?  It would be much appreciated.

Thanks!

Posted

I'm using that specific piece as a proof-of-concept.  I agree that it would be silly to move that particular piece into a block.  But in theory, is there a way to make a block aware of the current database?

Posted

Drat, that didn't work either.  Here's my modified block code (not working):

{{$database = \IPS\cms\Databases\Dispatcher::i()->databaseId;}}

<div class="cDevHeader" id="elDevDocs_header" style="background-image:url('/forums/uploads/set_resources_3/6554b6be8c0d829a8bf63ae0c82cf121_codebackground.jpg');">
  <h1 class="ipsType_pageTitle">
      {$database->_title}
	  <div class='ipsType_normal'>
	    {$database->_description}
	  </div>
  </h1>
</div>

Any suggestions?

Posted


Replace



with

{{$database = \IPS\cms\Databases::load(\IPS\cms\Databases\Dispatcher::i()->databaseId);}}

 

And keep in mind that this works ONLY if a database is being viewed!
You could use something like to have always a database selected

{{if \IPS\cms\Databases\Dispatcher::i()->databaseId}}
{{$databaseId = \IPS\cms\Databases\Dispatcher::i()->databaseId;}}
{{else}}
{{$databaseId = 1;}}
{{endif}}
{{$database = \IPS\cms\Databases::load($databaseId);}}


<div class="cDevHeader" id="elDevDocs_header" style="background-image:url('/forums/uploads/set_resources_3/6554b6be8c0d829a8bf63ae0c82cf121_codebackground.jpg');">
  <h1 class="ipsType_pageTitle">
      {$database->_title}
	  <div class='ipsType_normal'>
	    {$database->_description}
	  </div>
  </h1>
</div>

Hope this helps :)

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...