Jump to:

23490 Posts in 18996 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » Create file from Assets

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: 1187 Views
  • Mo
    Avatar
    Community Member
    508 Posts

    Create file from Assets Link to this post

    Hi All,

    Quick question, does anyone know if it is possible to generate a file (that will be put in the assets folder) from a template?

    I want to create an XML file with content from a form and generate the XML file from a template.

    I suppose I could use SimpleXML, would prefer to use a template if I can.

    Cheers in advance,

    Mo

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: Create file from Assets Link to this post

    Hi Mo,

    I think these two things may help...

    form the Filetest.php

          $folder = Folder::findOrMake('/FileTest/');
          $testfilePath = 'assets/FileTest/CreateWithFilenameHasCorrectPath.txt'; // Important: No leading slash
          $fh = fopen(BASE_PATH . '/' . $testfilePath, "w");
          fwrite($fh, str_repeat('x',1000000));
          fclose($fh);
                
          $file = new File();
          $file->Filename = $testfilePath;
          // TODO This should be auto-detected
          $file->ParentID = $folder->ID;
          $file->write();

    to render something without a page controller...

             $vd = new ViewableData();
             $ad = new ArrayData(array(
                'Data' => $dos
             ));
             $strHTML = $vd->customise($ad)->renderWith('MyTemplate');

  • Mo
    Avatar
    Community Member
    508 Posts

    Re: Create file from Assets Link to this post

    Oh cool, hopefully that will do what I want . I was thinking about renderWith but wasn't sure if it could be used like that. Fingers crossed!

    Cheers,

    Mo

    1187 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.