How to get content of block into Attribute
Permalink 2 users found helpful
Hi,
I need to get content of specific block into Attribute.
I'm trying to do this:
Concrete/Blocks/Myblock/View.php:
Concrete/Theme/Mytheme/default.php:
But it doesen't work. I recevied this bug:
Catchable fatal error: Object of class Page could not be converted to string in /home/www/restaurantcorsini.cz/subdomeny/www/indexjan/concrete/libraries/3rdparty/adodb/adodb-lib.inc.php on line 150
Or if You have some better ideas how to get content of block inside attribute, let me know. I appreciate all the help.
Thanks!
I need to get content of specific block into Attribute.
I'm trying to do this:
Concrete/Blocks/Myblock/View.php:
<form name="test"> <input type="hidden" value=" <?php echo $keyword1.", ".$keyword2.", ".$keyword3; ?> " name="page"> </form>
Concrete/Theme/Mytheme/default.php:
<?php Loader::model('collection_attributes'); $c->setAttribute('meta_keywords', $page); ?>
But it doesen't work. I recevied this bug:
Catchable fatal error: Object of class Page could not be converted to string in /home/www/restaurantcorsini.cz/subdomeny/www/indexjan/concrete/libraries/3rdparty/adodb/adodb-lib.inc.php on line 150
Or if You have some better ideas how to get content of block inside attribute, let me know. I appreciate all the help.
Thanks!
Unfortunately, Your solution is not working, too. I don't know why :( What's wrong?
Sorry, I'm a little confused. Is this going to be a form that anyone can submit and whatever they input will be set as to a specific attribute for the current page? Could you give more info on how this will be used?
I thought you were asking about forms, you had the beginnings of one in your question. I really don't know what you want to do.
No, at first You need to login. Then You add block and his content will be value for the attribute. In this attribute, every page will have their specific value which depends on what you type to the block on this page.
First of all, don't put your block inside the concrete directory -- put it in your site's top-level "blocks" directory instead.
If I'm understanding what you want to achieve, you need to process the form in the block controller and then set the attribute from there. I'm not sure this will even work as you want it to, though, because it's possible that setting the attribute in that way happens too late for the view to pick it up. Also, it sounds like you want this attribute to only be set for that one page view, but I think setting a page attribute in the way you want will set the attribute to that in a more permanent way (until it's set again by someone else using the form). If you do only want the "attribute" set for one page view, don't use an attribute at all -- instead just pass the value to the view from the controller function that processes the form.
Here's how you put the form in the block view:
Note that I've put each of your keywords into a separate input tag, because otherwise it will be annoying to parse out the individual values.
Then in your block's controller.php file, add this function:
Hope that helps.
-Jordan
If I'm understanding what you want to achieve, you need to process the form in the block controller and then set the attribute from there. I'm not sure this will even work as you want it to, though, because it's possible that setting the attribute in that way happens too late for the view to pick it up. Also, it sounds like you want this attribute to only be set for that one page view, but I think setting a page attribute in the way you want will set the attribute to that in a more permanent way (until it's set again by someone else using the form). If you do only want the "attribute" set for one page view, don't use an attribute at all -- instead just pass the value to the view from the controller function that processes the form.
Here's how you put the form in the block view:
Note that I've put each of your keywords into a separate input tag, because otherwise it will be annoying to parse out the individual values.
Then in your block's controller.php file, add this function:
function action_submit_form() { //First, retrieve the submitted form values: $keyword1 = $this->post('keyword1'); $keyword2 = $this->post('keyword1'); $keyword3 = $this->post('keyword1'); //To just pass the values back to the view so you can use them one time, do this: $this->set('keyword1', $keyword1); $this->set('keyword2', $keyword2); $this->set('keyword3', $keyword3); //Or if you want to actually set the page attribute, do this: $page = Page::getCurrentPage(); $page->setAttribute(CollectionAttributeKey::getByHandle('your_attribute_handle1'), $keyword1); //<-- change the handle and the value to what you want. $page->setAttribute(CollectionAttributeKey::getByHandle('your_attribute_handle2'), $keyword2); //<-- change the handle and the value to what you want. $page->setAttribute(CollectionAttributeKey::getByHandle('your_attribute_handle3'), $keyword3); //<-- change the handle and the value to what you want. }
Hope that helps.
-Jordan
jordan is absolutely right, just make sure that you are aware that when you call setAttribute you aren't setting a runtime attribute, this attribute is a true collection attribute that persists between requests and might override any existing attributes you already have.
I ran across this once cowboy coding something and it ended up not being what someone wanted, just putting that out there for you and anyone else that reads this later on.
I ran across this once cowboy coding something and it ended up not being what someone wanted, just putting that out there for you and anyone else that reads this later on.
Yes, that is what I exactly want to do. Than I call it in my default.php (using ) but I don't see anything, attribut wasn't set. So, maybe is necessary to set the value earlier. Have you any ideas?
<?php echo $c->getCollectionAttributeValue('klicova_slova') ?>
Yeah, I've made some changes and what's happened, it's working now!!
Here's the code:
view.php:
controller.php:
Now, I just need to assign $keyword1,$keyword2,$keyword3 to one attribute.
I hope that I can do it this way:
I thank You all for reply, solved.
Here's the code:
view.php:
Loader::model('collection_attributes'); $page = Page::getCurrentPage(); $page->setAttribute('meta_keywords', $keyword1); ?> <form method="post" action="<?php echo $this->action('submit_form'); ?>"> <input type="hidden" name="keyword1" value="<?php echo $keyword1; ?>"> <input type="hidden" name="keyword2" value="<?php echo $keyword2; ?>"> <input type="hidden" name="keyword3" value="<?php echo $keyword3; ?>"> </form>
controller.php:
Loader::model('collection_attributes'); function action_submit_form() { //First, retrieve the submitted form values: $keyword1 = $this->post('keyword1'); $keyword2 = $this->post('keyword1'); $keyword3 = $this->post('keyword1'); //To just pass the values back to the view so you can use them one time, do this: $this->set('keyword1', $keyword1); $this->set('keyword2', $keyword2); $this->set('keyword3', $keyword3); }
Now, I just need to assign $keyword1,$keyword2,$keyword3 to one attribute.
I hope that I can do it this way:
$page->setAttribute('meta_keywords', $keyword1.", ".$keyword2.", ".$keyword3);
I thank You all for reply, solved.
For those who want use this block, I upload this block in attachment. I gave there notes, to explain what and where you can change..
If you search around the forums you can find more detailed examples