如何通过从后端数据列表中获取数据来在laravel上制作动态标题

发布于 2025-01-10 08:06:32 字数 1233 浏览 0 评论 0原文

guest.blade.php

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="author" content="Yucel Yilmaz">
    <meta name="robots" content="index,follow">
    <meta name="publisher" content="Yücel Yilmaz">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@yield('title') | ecommerece</title>
    </head>
    <body>
    </body>
    </html>
    

cities-page-component.blade.php
<div>
@section('title', 'Laundry Near Me')
</div>

listing-page-component.blade.php
<div>
@section('title', 'Laundry Near Me')
</div>

如何通过laravel中的后端数据在产品详细信息页面中使标题动态

就像我有一个城市列表,在城市里有很多洗衣店。 在主页上,我们可以搜索城市,以便从数据库中显示城市列表。当用户点击任何城市时,页面将被定向到另一个包含洗衣店列表的页面所以我希望标题为{{城市名称}}中的洗衣店 同样,当用户点击任何洗衣店时,页面将定向到洗衣店的详细信息页面,因此我希望标题为 {{ 洗衣店名称 }} in {{ city name }}

guest.blade.php

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="author" content="Yucel Yilmaz">
    <meta name="robots" content="index,follow">
    <meta name="publisher" content="Yücel Yilmaz">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@yield('title') | ecommerece</title>
    </head>
    <body>
    </body>
    </html>
    

cities-page-component.blade.php
<div>
@section('title', 'Laundry Near Me')
</div>

listing-page-component.blade.php
<div>
@section('title', 'Laundry Near Me')
</div>

how do I make Title dynamic in the product detail page from the data from the backend in laravel

like an I have a list of cities, under the cities, there is a bunch of laundries.
On the main page, we can search for cities so the list of cities is shown from the database. when the user clicks any of the cities the page will be directed to another page with a list of laundries so I want the title to be laundries in {{ city name }}
same way when the user clicks on any laundry the page is directed detail page of laundries so the title I want to be {{ laundry name }} in {{ city name }}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撩动你心 2025-01-17 08:06:32

您可以通过模板继承为标题设置@yield

布局

<html>
    <head>
        <title>@yield('title')</title>
    </head>
    <body>
    ...

视图中的

@extends('layouts.app')
 
@section('title', $dynamicTitle)
 
@section('content')
    ...
@endsection

$dynamicTitle :您可以使用 $dynamicTitle@section('title') 自由分配值>$item->title 例如。取决于您的需求。

You can set @yield for title via template inheritance.

Layout

<html>
    <head>
        <title>@yield('title')</title>
    </head>
    <body>
    ...

Set $dynamicTitle in view :

@extends('layouts.app')
 
@section('title', $dynamicTitle)
 
@section('content')
    ...
@endsection

You are free to assign a value to the @section('title') using $dynamicTitle or $item->title for example. Depends on your needs.

萌能量女王 2025-01-17 08:06:32

您可以在返回城市记录时将城市标题存储为城市选择控制器中的会话变量

session()->put('cityName', city->city_title);

,并在洗衣房视图中使用它,

<h4>City Name : {{ Session('cityName') }} </h4>

同样在返回洗衣记录时将洗衣房标题保存为

session()->put('laundryName', laundry->laundry_title);

并在详细视图中使用它,例如

<h4>City Name : {{ Session('cityName') }} Laundry : {{ Session('laundryName') }} </h4>

You can store the City Title as session variable in cities selection controller when returning city record with

session()->put('cityName', city->city_title);

and use it in your laundries view as

<h4>City Name : {{ Session('cityName') }} </h4>

likewise save laundry Title when returning laundry record as

session()->put('laundryName', laundry->laundry_title);

and use it in your detail view like

<h4>City Name : {{ Session('cityName') }} Laundry : {{ Session('laundryName') }} </h4>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文