4 years ago

Blade file: Timestamp format and leading space

Posted 4 years ago by StuffedGoat

Hi! I'm building a Sitemap Generator and have some issues with it and kindly ask if you could give me some input.

  1. I want to change the date format of {{ unix() }} to match the standards of sitemap protocol. Is this in some way possible in a Blade file?
  2. You can see that I'm forwading a $tmp variable into the view to render this: <?xml version='1.0' encoding='UTF-8'?>. I also tried to put this into the Blade file: <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> But how ever I do this he puts a leading space before the line. :-) How can I get rid of this? (This produces an error since it expulses against the Sitemap protocol.

Here is my code:

// Method for creating the view

public function showSitemap()
    $pages = Page::all();       
    $tmp = "<?xml version='1.0' encoding='UTF-8'?>";        
    return response()->view('backend.pages.sitemap', ['pages' => $pages, 'tmp' => $tmp])->header('Content-Type', 'text/xml;charset=UTF-8');

// My Blade File

{!! $tmp !!}
<urlset xmlns="">
@foreach($pages as $page)
        <loc>{{ $page->url }}</loc>
        <lastmod>{{ unix() }}</lastmod>

And the error message: Alt Text

Please sign in or create an account to participate in this conversation.