Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8595905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:33:03+00:00 2026-06-12T00:33:03+00:00

I am doing some Drupal programming and have created yasnippets for common functions: db_select,

  • 0

I am doing some Drupal programming and have created yasnippets for common functions: db_select, db_delete etc.

I want to load them only when I am working on a Drupal file and not for a common php file. The task is this:

given a list of yasnippet files and the path of the currently opening file

if(path contains '/sites/all/modules')
{
    load all the snippets from the list
}

How to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:33:05+00:00Added an answer on June 12, 2026 at 12:33 am

    You have two options:

    1. Create a new mode called drupal-mode that inherits everything from php-mode and then define snippets for that mode, check out Derived Modes in the Emacs Manual on how to do that
    2. Add a function to the find-file hook that checks to see if the current buffer is in a particular directory and then load the snippets you want

    Either way you’ll be doing things based on the current directory or filename.

    find-file-hook example

    I haven’t tested this code but the concept is there. You’ll probably have to check the yas/load-directory-1 function to something else or mess around with parameters.

    (defun load-drupal-snippets ()
      (when (string-match-p "/sites/all/modules" (file-name-directory (buffer-file-name)))
        (yas--load-directory-1 "/path/to/drupal/snippets/" 'php-mode 'text-mode)))
    
    (add-hook 'find-file-hook 'load-drupal-snippets)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing some jquery animation. I have certain divs set up with an attribute of
I`m doing some web.config modifications with SPWebConfigModification class. When adding them to WebApplication and
I'm doing some content importing using the node import module in drupal. My problem
I'm doing some custom database work for a module for Drupal and I get
I have a form with some checkboxes in Drupal and I need to get
Doing some code reviews lately I came across a number of classes that have
I'm just starting out with JQuery in a Drupal environment. I have some thumbnails,
Problem I'm doing some maintenance and changes on a Drupal site, but I'm not
Am doing a local website in drupal. I have applied the theme 'Acquia Marina'
Doing some GIS programming I stumbled over the following strange issue: When I apply

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.