Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Metatags Bundle Laravel Package

copiaincolla/metatags-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require copiaincolla/metatags-bundle
    

    Add the bundle to config/bundles.php:

    CopiaIncolla\MetaTagsBundle\CopiaIncollaMetaTagsBundle::class => ['all' => true],
    
  2. Database Migration Run migrations to create the required tables:

    php bin/console doctrine:migrations:diff
    php bin/console doctrine:migrations:migrate
    
  3. Configure Routes Expose routes via config.yml:

    copia_incolla_metatags:
        bundles:
            - AppBundle
    

    Or annotate individual routes:

    /**
     * @Route("/product/{slug}", name="product_show", options={"ci_metatags_expose"=true})
     */
    
  4. First Use Case Access the admin panel at /admin/metatags to manually set meta tags for exposed routes.


Implementation Patterns

Route Exposure Strategies

  • Bundle-Level Exposure Configure in config.yml to expose all routes in a bundle:

    copia_incolla_metatags:
        bundles:
            - AppBundle
    
  • Route-Level Exposure Use annotations for granular control:

    /**
     * @Route("/blog/{id}", name="blog_post", options={"ci_metatags_expose"=true})
     */
    
  • Dynamic URL Loading For database-driven routes, use the UrlLoader service:

    $urls = $this->get('copia_incolla_metatags.url_loader')->loadUrls();
    

Twig Integration

Embed meta tags in templates:

{{ metatags() }}

Or target specific routes:

{{ metatags({ route: 'product_show', parameters: { slug: product.slug } }) }}

Admin Workflow

  1. Expose Routes: Ensure routes are marked for exposure.
  2. Load URLs: Run the cron job or service to populate the database:
    php bin/console copia_incolla:metatags:load-urls
    
  3. Manage Tags: Use the admin panel to set regex rules or manual overrides.

SEO Optimization

  • Regex Rules: Apply patterns to bulk-update meta tags (e.g., /blog/.*keywords: "blog,seo").
  • Fallbacks: Define default tags in config.yml:
    copia_incolla_metatags:
        defaults:
            title: "Default Title"
            description: "Default Description"
    

Gotchas and Tips

Pitfalls

  • Route Parameter Mismatch Ensure dynamic routes (e.g., /product/{slug}) are loaded with correct parameters. Use UrlLoader for complex cases:

    $loader = $this->get('copia_incolla_metatags.url_loader');
    $loader->addEntityLoader('product_show', 'App\Entity\Product', 'slug');
    
  • Caching Issues Clear the cache after exposing new routes:

    php bin/console cache:clear
    
  • Admin Permissions Secure the /admin/metatags route with Symfony’s security system:

    # config/packages/security.yaml
    access_control:
        - { path: ^/admin/metatags, roles: ROLE_ADMIN }
    

Debugging

  • Check Loaded URLs Verify routes are exposed via:

    php bin/console debug:container copia_incolla_metatags.url_loader
    

    Or dump the loaded URLs:

    $urls = $this->get('copia_incolla_metatags.url_loader')->getUrls();
    dump($urls);
    
  • Regex Validation Test regex rules in the admin panel before applying. Use tools like regex101.com for validation.

Extension Points

  • Custom Meta Tags Extend the MetaTag entity to support additional fields (e.g., twitter:card):

    // src/Entity/MetaTagExtension.php
    namespace App\Entity;
    use Doctrine\ORM\Mapping as ORM;
    
    #[ORM\Entity]
    class MetaTagExtension {
        #[ORM\Column(type: 'string', nullable: true)]
        private $twitterCard;
    }
    

    Update the bundle’s MetaTag entity to include the extension.

  • Event Listeners Trigger actions on meta tag updates (e.g., log changes):

    // src/EventListener/MetaTagListener.php
    namespace App\EventListener;
    use CopiaIncolla\MetaTagsBundle\Event\MetaTagEvent;
    
    class MetaTagListener {
        public function onMetaTagUpdate(MetaTagEvent $event) {
            // Custom logic
        }
    }
    

    Register in services.yaml:

    services:
        App\EventListener\MetaTagListener:
            tags:
                - { name: kernel.event_listener, event: copia_incolla.metatags.update, method: onMetaTagUpdate }
    

Performance

  • Batch Processing For large route sets, use batch loading:
    $loader->setBatchSize(100); // Adjust as needed
    
  • Database Indexing Add indexes to url and path columns in the metatags_url table for faster queries:
    CREATE INDEX idx_metatags_url_url ON metatags_url(url);
    CREATE INDEX idx_metatags_url_path ON metatags_url(path);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle