My first experience on concrete5

Permalink 1 user found helpful
Hi everybody.

I'm starting the development of block in concrete5.

I'm not newbie with PHP but i found concrete5 a bit difficult. Maybe a question of usual.

This is a discussion opened for the possible questions that i'll can have.

My block is "a liking system", for easy the concrete5 learning. The owner of site chooses a button style for adding it to on a page. Simple.

Maybe a same block exists but it's not my goal to search a block. I want to familiarize me with Concrete5 and his fundamentals.

So, i'm searching for now : how to get the block id on the current page ? I've tried with "$page -> getBlocks()" but it gets all blocks of the page. Me, i want just the block id of my block of the current page. It's possible ?

Thanks a lot for your answers.

Taramis
 
bbeng89 replied on at Permalink Reply
bbeng89
Are you trying to get the block id in a block view? If so, in the view you have a $b variable available to you which is a reference to the current block object. Using that you can do $b->getBlockID().

In concrete5 a page can contain many areas and an area can contain many blocks. So if you are on a page and know the area you want to retrieve your blocks from you can do
$blocks = $a->getAreaBlocksArray($c)


where $a is the area you want to retrieve the blocks from. This will return an array because it is possible for the area to contain multiple blocks, but if you know that you just want the first one you can access it by retrieving the first object in the array
$block = $blocks[0];


You might also want to check out the documentation on working with block objects here:http://www.concrete5.org/documentation/developers/blocks/working-wi...
Taramis replied on at Permalink Reply
Taramis
Yes, i'm trying to get the block id from the view.

So, i've tested your code like this in my controller :

public function view() {
         print($b->getBlockID());
      }


But nothing, i have this fatal error : Call to a member function getBlockID() on a non-object.

Do you know what can i do ?
bbeng89 replied on at Permalink Reply
bbeng89
Hey Taramis,
Sorry if I was unclear. I actually meant the view.php file, not the view() function in your controller. In the block controller you can access the block object with this code:

$block = $this->block;


Hope that helps. Sorry for the confusion!
mhawke replied on at Permalink Best Answer Reply
mhawke
Try:

$this->bID
Taramis replied on at Permalink Reply
Taramis
Thanks a lot mhawke.

$this->bID


This code works great ! :)
JohntheFish replied on at Permalink Reply
JohntheFish
Bear in mind that if you use the c5 copy/paste, bID is not unique so may give problems if are using bID to create a unique identifier.

This howto by mkly includes more:
http://www.concrete5.org/documentation/how-tos/developers/obtain-a-...
mhawke replied on at Permalink Reply
mhawke
Good to know. I've been using bID for ages and have never seen any issues. What kinds of things should I be watching out for?

Should we all be embedding mkly's code in our controllers? Better, should the core provide a rock-solid variable (like bID) that we can use to isolate instances of blocks on a page?
mhawke replied on at Permalink Reply
mhawke
So I stuck mkly's code in the view() function of my controller and called the variable '$uniqueID' and then wrapped my block in:

<div id=<?php echo $uniqueID ;?>">
Existing block code
.
.
.
</div>


which renders as:

[code]
<div id="BLOCK_1234">
.
.
.
</div>
{/code]

Cool!
JohntheFish replied on at Permalink Reply
JohntheFish
For many blocks, it just does not matter.

The main issue is where block code depends on a unique bID, such as tying javascript to a specific instance of a block, such as with sliders and galleries, where script attached to the block needs to know which gallery or slider to change. 2 blocks, same ID , and either you get a script collision and neither work, or one set of controls end up changing both pictures.

It can also give problems with duplicate css id's, illegal css, and consequently issues with jQuery selectors. Sometimes coupled to the previous issue. Or the 2nd block not getting any styling.

Before mkly's howto, I used to just add a big random number for such blocks.
mhawke replied on at Permalink Reply
mhawke
Good to know, thanks.

I guess I haven't built anything complicated enough to have conflicts, (or I've been lucky)
bbeng89 replied on at Permalink Reply
bbeng89
...or do that, haha. You're solution is much better. Thanks!
Taramis replied on at Permalink Reply
Taramis
Thank you, bbeng89 but your solution wasn't worked.

So, i've tested the solution of mhawke and it works great. :)
Taramis replied on at Permalink Reply
Taramis
Re-hi everybody.

I have another question. I want use and get images in my view.php.

Do you know where can i put my images and how can i get it in my view.php (or controller also, by a function for example) ?

Thanks a lot for your answer. ;)
mhawke replied on at Permalink Reply
mhawke
Are you building this block from scratch? Because you really just need to use this:

http://www.concrete5.org/marketplace/addons/designer-content/...

It will show you how it's all done, including images.
Taramis replied on at Permalink Reply
Taramis
Yes, i build my block from zero for learn well the rudiments of Concrete5.

So, sometimes i'm a bit lost. ^^

Thank you again for your answer. I'll look your link now. ;)
mhawke replied on at Permalink Reply
mhawke
The Designer Content add-on is one of the best things to help you learn as well as these two as well:

http://www.concrete5.org/marketplace/addons/c5-boilerplate/...

http://www.concrete5.org/marketplace/addons/custom-objects-demo/...
Taramis replied on at Permalink Reply
Taramis
Hi mhwake,

If i want use images for my block, i need use the file manager. But, what i want, it's use my images like icons for my block, not images like photos, illustrations.

For example : if i build a custom menu block, i would like use some icons for my menu. Have i need really use the file manager for it ? It's a bit tedious, i think, to use it only for this.

I cannot use a folder (like "/blocks/myblock/images/") and use a path (relative or absolute ?) for do it ?
mhawke replied on at Permalink Reply
mhawke
Sure, just put these images in a sub-folder inside your block's folder and then use this to grab them:
<img src="<?php echo $this->getBlockPath();?>/images/yourimage.png">
Taramis replied on at Permalink Reply
Taramis
Thanks a lot mhawke ! :)
mhawke replied on at Permalink Reply
mhawke
This helps me a lot:

http://www.weblicating.com/doku/doku.php?id=cheatsheet#.UgYvKZJwqdw...

It doesn't have much about blocks but it has lots of other code examples.

Also, I learn a lot about what functions are available in concrete5 by just looking at the code. Most relevant block functions are in '[root]/concrete/core/libraries/block_view.php'
Taramis replied on at Permalink Reply
Taramis
Hi everybody,

I have a question. I'm understanding the architecture of Concrete5 only now. Yes, it's very long. xD

So if i have understand well :

Collections
-|Page
--|Areas
---|Blocks

So, if i want to add a new area's type (handle). How can i do ?

For example, i want to add an area handle "Footer" in my C5 sites. How can i do it ?

Taramis.
bbeng89 replied on at Permalink Reply
bbeng89
All you need to do is in your theme add a bit of PHP code like this:

<?php
$a = new Area('Footer');
$a->display($c);
?>


Also, since its the footer and I assume it will likely be the same on every page, you might want to make it a global area:

<?php
$a = new GlobalArea('Footer');
$a->display($c);
?>
Taramis replied on at Permalink Reply
Taramis
WoW! Fantastic, no... magic! :)

I wasn't imagined that it works automatically with this way.

Thank's a lot!
bbeng89 replied on at Permalink Reply
bbeng89
Not a problem, glad I could help! Concrete5 does make it incredibly easy to convert HTML templates into themes.

Good luck!
mhawke replied on at Permalink Reply
mhawke
Just to expand on bbeng89's answer... If you have an 'elements/footer.php' file in your theme folder, you might want to add your new area inside the 'footer.php' so it's added to the bottom of every page.

Also, I believe the 'official' way to display a Global Area is to leave out the $c in the brackets like this:

$a->display();


Putting the $c in a Global Area used to crash things but perhaps newer versions are more forgiving.
Taramis replied on at Permalink Reply
Taramis
Yes, i proceeded like this.

<?php
    $af = new GlobalArea('Footer');
    $af->display();
?>


Because in "header.php", i found some GlobalArea defined like this. So, i do it well, cool ^^

Thank you for complement, Mhawke :)
Taramis replied on at Permalink Reply
Taramis
I use since recently the framework Bootstrap. Do you think that it will be easily to integrate Bootstrap in my theme ?

Taramis.
bbeng89 replied on at Permalink Reply
bbeng89
Yes, it is very easy to integrate with bootstrap. I've used bootstrap for most of my themes actually. You can do things like this (prior to bootstrap 3):

<div class="row-fluid">
    <div class="span4">
        <?php
       $a = new Area('Sidebar Content');
       $a->display($c);
   ?>
    </div>
    <div class="span8">
        <?php
       $a = new Area('Main Content');
       $a->display($c);
   ?>
    </div>
</div>


So you can see it makes it really easy create layouts for different page types.
Taramis replied on at Permalink Reply
Taramis
Super! It really like i've thinked. :)

Thx again.
Taramis replied on at Permalink Reply
Taramis
Hi everybody,

I would like to ask you if possible to give me the links of your C5 website.

I want see some examples of C5 webdesign possibilities.

Taramis.
simonknibbs replied on at Permalink Reply
simonknibbs
mhawke replied on at Permalink Reply
mhawke
I'm very impressed with these folks:

http://linedesigngraphics.com/portfolio.html...

and concrete5 has it's own 'showcase' of sites here:

http://www.concrete5.org/about/showcase/...
Taramis replied on at Permalink Reply
Taramis
Thanks simonknibbs and mhawke for your links.

At my evolution's stade, i have a bit bad to imagine that it's possible to make as of things with C5. I'm really amazed.

Moreover, the only thing it's that for make C5 sites like those examples, it will be more easily without C5 if the site isn't CMS but the goal is to make CMS so ...

I find that WP is more easy than C5. But in my new job, they use C5... so i need to understand and practice C5.
Taramis replied on at Permalink Reply 2 Attachments
Taramis
I have a strange issue.

When i click on "Add a sub-page", just the edition page comes. I don't have the box for add a new sub-page.

Bug or not bug ? Do you know where can this come ?

Taramis.

EDIT: i have put two screenshot (2 attachments of this post)

First : a theme who works correctly with the adding of subpage
Second : my theme who doesn't work with the adding of subpage :(
Taramis replied on at Permalink Reply
Taramis
Hi everybody.

With my dashboard News extension, i've created an attribute for the single page "The news" but if we imagine that this site is made for a customer, he can attribute the attribute "News listing" at the others pages. I wouldn't like possible that he can do it.

So i have a question. How can i restrict a page attribute for one page only ?