vmoulin78 / codeigniter-layout-library

CodeIgniter Template Library
MIT License
24 stars 9 forks source link

How to pass $data to blocks or inner templates? #5

Closed albertone closed 7 years ago

albertone commented 7 years ago

Hi,

I have testing the library and I would like to use include_template() or block() functions inside a template for generate dynamic content like menus but it does not possible pass data to the blocks or templates included.

Actually I do that with _loadview() and _trigger_contentsection() as you describes on readme.

For example, if we have a template which have a header with dynamic menu, what is the way to implement it using the template?

vmoulin78 commented 7 years ago

Hello Albertone,

In fact, what you've done is just the right way of doing what you want. The template system with the _includetemplate() and block() methods are for static code.

If your menu is built dynamically, you have to create a view (or many views if necessary) for the menu and then, use the _loadview() and _trigger_contentsection() methods.

So, you can't pass data to a template or a block but the $CI variable is available If you have a session data _userprofile, you can access it with: $CI->session->user_profile

Vince

albertone commented 7 years ago

Hello @vmoulin78

Thanks for you answer. So we can close this issue.

Thank you for your attention. Alberto