首页 \ 问答 \ Go运行时如何用Go编写?(How is it possible for the Go runtime to be written in Go?)

Go运行时如何用Go编写?(How is it possible for the Go runtime to be written in Go?)

我从Go 1.4中读到 ,Go运行时是用Go本身(而不是C语言)编写的。

这怎么可能? 如果Go程序在运行时运行,并且运行时是Go程序,那么运行时是否运行在自身之上?


I read that from Go 1.4, the Go runtime is written in Go itself (rather than in C).

How is this possible? If Go programs run on top of the runtime, and the runtime is a Go program, does the runtime run on top of itself?


原文:https://stackoverflow.com/questions/34756262
更新时间:2024-02-12 10:02

最满意答案

显然,您无法直接修改search-theme-form.tpl.php的HTML,因为这不是正确的方法。 所以我添加类和onFocus和onBlur属性是问题所在。

正确的方法是修改主题template.php文件。 基本上我们将使用form_alter()来修改表单元素。 由于使用HTML方式是错误的。 看看下面的代码(取自: 这里

<?php
/**
* Override or insert PHPTemplate variables into the search_theme_form template.
*
* @param $vars
*   A sequential array of variables to pass to the theme template.
* @param $hook
*   The name of the theme function being called (not used in this case.)
*/
function yourthemename_preprocess_search_theme_form(&$vars, $hook) {
  // Note that in order to theme a search block you should rename this function
  // to yourthemename_preprocess_search_block_form and use
  // 'search_block_form' instead of 'search_theme_form' in the customizations
  // bellow.

  // Modify elements of the search form
  $vars['form']['search_theme_form']['#title'] = t('');

  // Set a default value for the search box
  $vars['form']['search_theme_form']['#value'] = t('Search this Site');

  // Add a custom class and placeholder text to the search box
  $vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 
                                                              'onfocus' => "if (this.value == 'Search this Site') {this.value = '';}",
                                                              'onblur' => "if (this.value == '') {this.value = 'Search this Site';}");

  // Change the text on the submit button
  //$vars['form']['submit']['#value'] = t('Go');

  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_theme_form']['#printed']);
  $vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);

  $vars['form']['submit']['#type'] = 'image_button';
  $vars['form']['submit']['#src'] = path_to_theme() . '/images/search.jpg';

  // Rebuild the rendered version (submit button, rest remains unchanged)
  unset($vars['form']['submit']['#printed']);
  $vars['search']['submit'] = drupal_render($vars['form']['submit']);

  // Collect all form elements to make it easier to print the whole form.
  $vars['search_form'] = implode($vars['search']);
}
?>

yourthemename_preprocess_search_theme_form - 'yourthemename'显然会反映您的自定义主题的名称。 基本上代码是不言自明的。 什么评论和所有。

所以,基本上就是它的工作方式。


Apparently, you cannot directly modify the HTML in search-theme-form.tpl.php since thats not the right way to do it. So my adding the class and onFocus and onBlur attributes was the problem.

The correct way to do it is to modify the themes template.php file. Basically we will be using form_alter() to modify the form elements. Since using the HTML way is wrong. Take a look at the code below (taken from : here )

<?php
/**
* Override or insert PHPTemplate variables into the search_theme_form template.
*
* @param $vars
*   A sequential array of variables to pass to the theme template.
* @param $hook
*   The name of the theme function being called (not used in this case.)
*/
function yourthemename_preprocess_search_theme_form(&$vars, $hook) {
  // Note that in order to theme a search block you should rename this function
  // to yourthemename_preprocess_search_block_form and use
  // 'search_block_form' instead of 'search_theme_form' in the customizations
  // bellow.

  // Modify elements of the search form
  $vars['form']['search_theme_form']['#title'] = t('');

  // Set a default value for the search box
  $vars['form']['search_theme_form']['#value'] = t('Search this Site');

  // Add a custom class and placeholder text to the search box
  $vars['form']['search_theme_form']['#attributes'] = array('class' => 'NormalTextBox txtSearch', 
                                                              'onfocus' => "if (this.value == 'Search this Site') {this.value = '';}",
                                                              'onblur' => "if (this.value == '') {this.value = 'Search this Site';}");

  // Change the text on the submit button
  //$vars['form']['submit']['#value'] = t('Go');

  // Rebuild the rendered version (search form only, rest remains unchanged)
  unset($vars['form']['search_theme_form']['#printed']);
  $vars['search']['search_theme_form'] = drupal_render($vars['form']['search_theme_form']);

  $vars['form']['submit']['#type'] = 'image_button';
  $vars['form']['submit']['#src'] = path_to_theme() . '/images/search.jpg';

  // Rebuild the rendered version (submit button, rest remains unchanged)
  unset($vars['form']['submit']['#printed']);
  $vars['search']['submit'] = drupal_render($vars['form']['submit']);

  // Collect all form elements to make it easier to print the whole form.
  $vars['search_form'] = implode($vars['search']);
}
?>

In yourthemename_preprocess_search_theme_form - 'yourthemename' will obviously reflect the name of your custom theme. Basically the code is self-explanatory. what with the comments and all.

So, basically thats the way it works.

相关问答

更多
  • 我无法看到你在哪里使用你的主题功能,你可以尝试在块体中渲染你的主题功能 $block['content'] = theme('test'); I can't see where you used your theme function, you can try to render your theme function in block body $block['content'] = theme('test');
  • 主菜单可用作块。 所以你可以把他带到这个地区。 这是一个很好的做法。 另外不要忘记清除drupal /浏览器缓存。 如果在preprocess_page()或任何其他预处理函数中定义自定义变量,则不应使用渲染函数,例如使用print $main_menu 。 另外试试看这个 Main menu available as block. So you can just put him to this region. It's good practice. Also don't forget to clear d ...
  • 主题函数被设置为使用模板或函数来生成标记,它将永远不会使用这两者,因为它没有意义。 对于使用模板的主题函数,必须在hook_theme定义它时定义它。 模板+预处理功能和主题功能确实做同样的事情:产生标记。 这取决于哪种方法最好使用的情况,这就是为什么我们有两个。 关于模板的好处是,它允许用户更改标记,而不需要了解PHP或Drupal。 高速缓存 Drupal缓存主题中定义的所有模板和主题函数,当您创建新模板和主题函数时,需要清除缓存,这可以通过以下方式完成: 使用匆匆 清除admin/settings/p ...
  • 正如你在theme()中看到的那样,Drupal只会根据drupal_discover_template()实际使用模板。 您应该尝试弄清楚是否是这种情况。 将一些调试代码放在includes / theme.inc中的theme()函数中,以查看drupal_discover_template()为模板调用返回的内容。 能找到吗? 如果不: 在drupal_discover_template()放置一些调试代码,以找出Drupal认为它不再是模板的位置。 我的直觉是,这是由于模板文件所在的子目录,但是你没 ...
  • 在主题的template.php文件中,在hook_js_alter使用此代码。 function [YOUR_THEME]_js_alter(&$js) { $jqKey = "my-new-jquery"; // a key for new jquery file entry $js[$jqKey] = $js['misc/jquery.js']; // copy the default jquery settings, so you don't have to re-type them ...
  • 修复了以下内容: function_exists('search_theme') or drupal_load('module','search'); function_exists('template_preprocess_search_results') or module_load_include('inc','search','search.pages'); 我不喜欢它。 Fixed it with the following: function_exists('search_theme') or ...
  • 上面的代码和你的假设是正确的。 我尝试在我的本地使用上面的代码它工作正常,因此它将page--article.tpl.php作为页面tpl,对于节点tpl,它采用了node--article.tpl.php 。 检查步骤: 用template.php编写的hook_preprocess_page将始终优先。 The above code and your assumption is right. I tried using the above code in my local it worked fine, ...
  • 解决任何Drupal问题的第一步:您是否尝试过清除缓存? (这是Drupal相当于“你试过把它关掉然后再打开吗?”) 如何清除缓存:如果以管理员身份登录站点,请转至配置>开发>性能。 您应该看到“清除所有缓存”按钮。 如果这不起作用:您是否检查过Drupal文档? https://www.drupal.org/node/171209 如果聚合和压缩CSS文件(配置>开发>性能中的设置)会发生什么? Step number one in solving any Drupal problem: Have you ...
  • 显然,您无法直接修改search-theme-form.tpl.php的HTML,因为这不是正确的方法。 所以我添加类和onFocus和onBlur属性是问题所在。 正确的方法是修改主题template.php文件。 基本上我们将使用form_alter()来修改表单元素。 由于使用HTML方式是错误的。 看看下面的代码(取自: 这里 )
  • 尝试更改表单调用的提交函数,而不是更改表单操作的URL: /** * Implementation of hook_form_alter() */ function mymodule_form_alter(&$form, &$form_state, $form_id) { if($form_id == 'search_block_form') { $form['#submit'][] = 'mymodule_form_submit'; } } /** * Process a block ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)