Jump to:

23001 Posts in 11702 Topics by 2827 members

General Questions

SilverStripe Forums » General Questions » FirstParagraph/LimitWordCount not working in custom DataObjectSet

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 435 Views
  • prawnstar
    Avatar
    Community Member
    116 Posts

    FirstParagraph/LimitWordCount not working in custom DataObjectSet Link to this post

    When creating a new DataObjectSet, things like FirstParagraph and LimitWordCount don't seem to work with the data from the new Object.

    In short, I'm trying to get an object, manipulate the data, create a new object and send that along to the templates.

    public function getProducts() {
    $products = DataObject::get("Product", "ProductFeature", "", "", "");
    $ProductsDataObject = new DataObjectSet();
    $multiarray = array();

    foreach($products as $product) {
    $prodtitle = $product->MenuTitle;
    $prodcontent = $product->Content;

    ...Some other code here...

    $proddata = array(
    "prodtitle"=>$prodtitle,
    "prodcontent"=>$prodcontent,
    ...other array data here...
    );
    array_push($multiarray, $proddata);
    $ProductsDataObject->push(new ArrayData($proddata));
    }
    return $ProductsDataObject;
    }

    In my templates control loop I'm using $prodcontent.FirstParagraph, but getting nothing.

    --
    Chris

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: FirstParagraph/LimitWordCount not working in custom DataObjectSet Link to this post

    Tha is because when use "via" the databoject itself it will yeild a DBField type object, but when used in the way above it will yeild a literal string primitive (i think!) - but not the same DBField object. It is the DBField type that contains the methdods.

  • prawnstar
    Avatar
    Community Member
    116 Posts

    Re: FirstParagraph/LimitWordCount not working in custom DataObjectSet Link to this post

    Thanks swaiba!

    Forgive the dumb follow-up question, but...

    Instead of creating a new DataObjectSet, is it possible to inject my custom key/values into the DOS that gets returned with the page?

    (I'm not sure I'm asking the question correctly. Unfortunately I'm a better php hacker than a php programmer.)

    Thanks,
    Chris

    435 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.