3

I am using Symfony2 with twig in it and I have large files (>100MB), which I want to parse and write some information from it into the HTML page. If I use my own Twig extension I get a memory exhaustion error. So is there a way to parse txt file straight from the twig file?

small file example:

1
003.00 001.00 
000.00 005.00 

result in HTML:

3+x+5xy
Matteo
  • 37,680
  • 11
  • 100
  • 115
H.W.
  • 343
  • 1
  • 5
  • 21
  • 2
    Hey H.W. Could you provide the code you use to read and output the text file. Also please note that Twig is a templating language. You are doing file reading now. That looks like the wrong way. – mvbrakel Mar 18 '15 at 11:03
  • As Design consideration, i suggest you to treat the file as storage and access to it via a (sort of, not doctrine) repository. So do the work in the controller (better if the controller call a dedicated service) and return it to the view (twig) – Matteo Mar 18 '15 at 11:08
  • mvbrakel I don't have the code yet. But I'm afraid if I load the whole file and give it to the Twig template I get memeory error, if the file is large. – H.W. Mar 18 '15 at 11:41

1 Answers1

1

How about creating a custom extension and using a generator? (http://php.net/manual/en/language.generators.overview.php)

eRIZ
  • 1,477
  • 16
  • 32