News & Newsletter

Simple news (or blog) and newsletter plugin with statistics, mail logs, components and export & import.

Back to News & Newsletter Support

michal.malecki.eko13095
michal.malecki.eko13095

Hi Could someone help me with multi language. I added news in 3 language versions but I still see the only one - eng. What could do wrong?

gergo85
gergo85

Use this similar code:

function onStart()
{
    $this['news'] = '';
    $sql = DB::table('news_posts')->where('status', 1)->orderBy('published_at', 'desc')->get();

    foreach ($sql as $item) {
        if (Schema::hasTable('rainlab_translate_attributes')) {
            $translate = json_decode(DB::table('rainlab_translate_attributes')->where('locale', App::getLocale())->where('model_id', $item->id)->where('model_type', 'Indikator\News\Models\Posts')->pluck('attribute_data'), true);

            if ($translate['name'] != '') {
                $item->name = $translate['name'];
            }
            if ($translate['introductory'] != '') {
                $item->introductory = $translate['introductory'];
            }
        }

        $this['news'] .= '
            <div class="news">
                <h2>'.$item->name.'</h2>
                <p>'.$item->introductory.'</p>
                <p><a href="/news/'.$item->.slug'">More...</a></p>
            </div>';
    }
}
michal.malecki.eko13095
michal.malecki.eko13095

Thank you for answer Where can I put this code? Inside a page where I display a post?

gergo85
gergo85

Use this sample code in current page:

HTML

<div id="posts">
    {% for post in posts %}
    <div class="post">
        <h2>{{ post.name }}</h2>
        <p>{{ post.introductory }}</p>
        <p><a href="/news/{{ post.slug }}">More...</a></p>
    </div>
    {% endfor %}
</div>

PHP

function onStart()
{
    $this['posts'] = Indikator\News\Models\Posts::orderBy('published_at', 'desc')->get();
}
gergo85
gergo85

I solved this problem. Now the front-end components work properly.

1-5 of 5