Sitemap with laravel
Asked Answered
B

4

6

I works in my project by LARAVEL.

I want to make sitemap. This is my controller:

class SitemapController extends BaseController {
        public function index() {
                header("Content-Type: text/xml;charset=utf-8");
                return View::make('sitemap');
        }
}

And This is my view sitemap.blade.php:

{{<?xml version="1.0" encoding="UTF-8" ?>}}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
        <url>
                <loc>{{url()}}</loc>
                <priority>0.5</priority>
        </url>
        .
        .
        .
</urlset>

But result not appeared as XML. It appeared as a normal text.

Breeding answered 5/5, 2014 at 9:18 Comment(2)
did u solved ur issue by this method? because i just started using this controller view method.Multicellular
yes, I wrote solution at answers.Breeding
B
6

It works when I used:

{{'<?xml version="1.0" encoding="UTF-8" ?>'}}

and I updated my controller as:

class SitemapController extends BaseController {
        public function index() {
                $content = View::make('sitemap');
                return Response::make($content)->header('Content-Type', 'text/xml;charset=utf-8');
        }
}
Breeding answered 21/5, 2014 at 14:55 Comment(3)
i did have to use {{ '<'.'?'.'xml version="1.0" encoding="UTF-8"?>' }} to be able to get it to work. (laravel 4.2)Caston
In laravel 5 I used {!! '<'.'?'.'xml version="1.0" encoding="UTF-8"?>' !!}Viral
I just ditched blade for this line and used <?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> to get it working for meBemock
A
5

I suggest you should use this package https://github.com/RoumenDamianoff/laravel-sitemap

Installation

Add the following to your composer.json file :

"roumen/sitemap": "dev-master"

Then register this service provider with Laravel :

'Roumen\Sitemap\SitemapServiceProvider',

Publish configuration file. (OPTIONAL)

php artisan config:publish roumen/sitemap
Appendicular answered 22/7, 2014 at 7:35 Comment(0)
F
1

Wrap the XML declaration in single quotes:

{{'<?xml version="1.0" encoding="UTF-8" ?>'}}

Works for my in Laravel.

Foible answered 5/5, 2014 at 19:52 Comment(0)
N
1

Add the XML declaration like this:

<?php echo '<?xml version="1.0" encoding="UTF-8"?>' ?>
Narcolepsy answered 15/7, 2015 at 10:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.